r247194 - [Concepts] Add diagnostic; invalid specifier on function or variable concept declaration
Nathan Wilson via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 9 14:48:31 PDT 2015
Author: nwilson
Date: Wed Sep 9 16:48:31 2015
New Revision: 247194
URL: http://llvm.org/viewvc/llvm-project?rev=247194&view=rev
Log:
[Concepts] Add diagnostic; invalid specifier on function or variable concept declaration
Summary: Diagnose variable and function concept declarations when an invalid specifier appears
Reviewers: rsmith, aaron.ballman, faisalv, fraggamuffin, hubert.reinterpretcast
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D12435
Added:
cfe/trunk/test/CXX/concepts-ts/
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/p2.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=247194&r1=247193&r2=247194&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 9 16:48:31 2015
@@ -1980,6 +1980,9 @@ def err_var_concept_not_initialized : Er
"variable concept declaration must be initialized">;
def err_function_concept_exception_spec : Error<
"function concept cannot have exception specification">;
+def err_concept_decl_invalid_specifiers : Error<
+ "%select{variable|function}0 concept cannot be declared "
+ "'%select{thread_local|inline|friend|constexpr}1'">;
// 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=247194&r1=247193&r2=247194&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Sep 9 16:48:31 2015
@@ -5876,8 +5876,26 @@ Sema::ActOnVariableDeclarator(Scope *S,
if (D.getDeclSpec().isConstexprSpecified())
NewVD->setConstexpr(true);
- if (D.getDeclSpec().isConceptSpecified())
+ if (D.getDeclSpec().isConceptSpecified()) {
NewVD->setConcept(true);
+
+ // C++ Concepts TS [dcl.spec.concept]p2: A concept definition shall not
+ // be declared with the thread_local, inline, friend, or constexpr
+ // specifiers, [...]
+ if (D.getDeclSpec().getThreadStorageClassSpec() == TSCS_thread_local) {
+ Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
+ diag::err_concept_decl_invalid_specifiers)
+ << 0 << 0;
+ NewVD->setInvalidDecl(true);
+ }
+
+ if (D.getDeclSpec().isConstexprSpecified()) {
+ Diag(D.getDeclSpec().getConstexprSpecLoc(),
+ diag::err_concept_decl_invalid_specifiers)
+ << 0 << 3;
+ NewVD->setInvalidDecl(true);
+ }
+ }
}
// Set the lexical context. If the declarator has a C++ scope specifier, the
@@ -7502,6 +7520,30 @@ Sema::ActOnFunctionDeclarator(Scope *S,
// C++ Concepts TS [dcl.spec.concept]p2: Every concept definition is
// implicity defined to be a constexpr declaration (implicitly inline)
NewFD->setImplicitlyInline();
+
+ // C++ Concepts TS [dcl.spec.concept]p2: A concept definition shall not
+ // be declared with the thread_local, inline, friend, or constexpr
+ // specifiers, [...]
+ if (isInline) {
+ Diag(D.getDeclSpec().getInlineSpecLoc(),
+ diag::err_concept_decl_invalid_specifiers)
+ << 1 << 1;
+ NewFD->setInvalidDecl(true);
+ }
+
+ if (isFriend) {
+ Diag(D.getDeclSpec().getFriendSpecLoc(),
+ diag::err_concept_decl_invalid_specifiers)
+ << 1 << 2;
+ NewFD->setInvalidDecl(true);
+ }
+
+ if (isConstexpr) {
+ Diag(D.getDeclSpec().getConstexprSpecLoc(),
+ diag::err_concept_decl_invalid_specifiers)
+ << 1 << 3;
+ NewFD->setInvalidDecl(true);
+ }
}
// If __module_private__ was specified, mark the function accordingly.
Added: cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/p2.cpp?rev=247194&view=auto
==============================================================================
--- cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/p2.cpp (added)
+++ cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/p2.cpp Wed Sep 9 16:48:31 2015
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
+
+template<typename T> concept thread_local bool VCTL = true; // expected-error {{variable concept cannot be declared 'thread_local'}}
+
+template<typename T> concept constexpr bool VCC = true; // expected-error {{variable concept cannot be declared 'constexpr'}}
+
+template<typename T> concept inline bool FCI() { return true; } // expected-error {{function concept cannot be declared 'inline'}}
+
+struct X {
+ template<typename T> concept friend bool FCF() { return true; } // expected-error {{function concept cannot be declared 'friend'}}
+};
+
+template<typename T> concept constexpr bool FCC() { return true; } // expected-error {{function concept cannot be declared 'constexpr'}}
More information about the cfe-commits
mailing list