r259159 - [Concepts] Implement a portion of Concepts TS[dcl.spec.concept]p5 and p6:
Nathan Wilson via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 28 20:44:00 PST 2016
Author: nwilson
Date: Thu Jan 28 22:43:59 2016
New Revision: 259159
URL: http://llvm.org/viewvc/llvm-project?rev=259159&view=rev
Log:
[Concepts] Implement a portion of Concepts TS[dcl.spec.concept]p5 and p6:
Diagnose if the return type of a function concept or declaration type of a
variable concept is not bool.
Reviewers: hubert.reinterpretcast
Differential Revision: http://reviews.llvm.org/D16163
Added:
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=259159&r1=259158&r2=259159&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 28 22:43:59 2016
@@ -2074,6 +2074,10 @@ def err_concept_decl_invalid_specifiers
"'%select{thread_local|inline|friend|constexpr}1'">;
def err_function_concept_with_params : Error<
"function concept cannot have any parameters">;
+def err_function_concept_bool_ret : Error<
+ "declared return type of function concept must be 'bool'">;
+def err_variable_concept_bool_decl : Error<
+ "declared type of variable concept must be 'bool'">;
// C++11 char16_t/char32_t
def warn_cxx98_compat_unicode_type : Warning<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=259159&r1=259158&r2=259159&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 28 22:43:59 2016
@@ -6001,6 +6001,15 @@ Sema::ActOnVariableDeclarator(Scope *S,
<< 0 << 3;
NewVD->setInvalidDecl(true);
}
+
+ // C++ Concepts TS [dcl.spec.concept]p6: A variable concept has the
+ // following restrictions:
+ // - The declared type shall have the type bool.
+ if (!Context.hasSameType(NewVD->getType(), Context.BoolTy) &&
+ !NewVD->isInvalidDecl()) {
+ Diag(D.getIdentifierLoc(), diag::err_variable_concept_bool_decl);
+ NewVD->setInvalidDecl(true);
+ }
}
}
@@ -7682,6 +7691,14 @@ Sema::ActOnFunctionDeclarator(Scope *S,
}
// C++ Concepts TS [dcl.spec.concept]p5: A function concept has the
+ // following restrictions:
+ // - The declared return type shall have the type bool.
+ if (!Context.hasSameType(FPT->getReturnType(), Context.BoolTy)) {
+ Diag(D.getIdentifierLoc(), diag::err_function_concept_bool_ret);
+ NewFD->setInvalidDecl();
+ }
+
+ // C++ Concepts TS [dcl.spec.concept]p5: A function concept has the
// following restrictions:
// - The declaration's parameter list shall be equivalent to an empty
// parameter list.
Modified: cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp?rev=259159&r1=259158&r2=259159&view=diff
==============================================================================
--- cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp (original)
+++ cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp Thu Jan 28 22:43:59 2016
@@ -11,3 +11,15 @@ concept bool fcpp(Ts... ts) { return tru
template<typename T>
concept bool fcpva(...) { return true; } // expected-error {{function concept cannot have any parameters}}
+
+template<typename T>
+concept const bool fcrtc() { return true; } // expected-error {{declared return type of function concept must be 'bool'}}
+
+template<typename T>
+concept int fcrti() { return 5; } // expected-error {{declared return type of function concept must be 'bool'}}
+
+template<typename T>
+concept float fcrtf() { return 5.5; } // expected-error {{declared return type of function concept must be 'bool'}}
+
+template<typename T>
+concept decltype(auto) fcrtd(void) { return true; } // expected-error {{declared return type of function concept must be 'bool'}}
Added: cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp?rev=259159&view=auto
==============================================================================
--- cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp (added)
+++ cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp Thu Jan 28 22:43:59 2016
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
+
+template<typename T>
+concept bool vc { true };
+
+template<typename T>
+struct B { typedef bool Boolean; };
+
+template<int N>
+B<void>::Boolean concept vctb(!0);
+
+template<typename T>
+concept const bool vctc { true }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept int vcti { 5 }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept float vctf { 5.5 }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept auto vcta { true }; // expected-error {{declared type of variable concept must be 'bool'}}
+
+template<typename T>
+concept decltype(auto) vctd { true }; // expected-error {{declared type of variable concept must be 'bool'}}
More information about the cfe-commits
mailing list