Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 720bfb4

Browse files
[Concepts] Add diagnostic: non template declaration
Summary: Adding diagnostic for concepts declared as non template (function or variable) Reviewers: faisalv, fraggamuffin, rsmith, hubert.reinterpretcast Subscribers: nwilson, cfe-commits Differential Revision: http://reviews.llvm.org/D11490 Patch by Nathan Wilson! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243690 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d0322e9 commit 720bfb4

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

Diff for: include/clang/Basic/DiagnosticSemaKinds.td

+2
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,8 @@ def note_private_extern : Note<
19651965
"use __attribute__((visibility(\"hidden\"))) attribute instead">;
19661966

19671967
// C++ Concepts TS
1968+
def err_concept_decl_non_template : Error<
1969+
"'concept' can only appear on the definition of a function template or variable template">;
19681970
def err_concept_decls_may_only_appear_in_namespace_scope : Error<
19691971
"concept declarations may only appear in namespace scope">;
19701972
def err_function_concept_not_defined : Error<

Diff for: lib/Sema/SemaDecl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -4865,6 +4865,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
48654865
// C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
48664866
// applied only to the definition of a function template or variable
48674867
// template, declared in namespace scope
4868+
if (!TemplateParamLists.size()) {
4869+
Diag(D.getDeclSpec().getConceptSpecLoc(),
4870+
diag::err_concept_decl_non_template);
4871+
return nullptr;
4872+
}
4873+
48684874
if (!DC->getRedeclContext()->isFileContext()) {
48694875
Diag(D.getIdentifierLoc(),
48704876
diag::err_concept_decls_may_only_appear_in_namespace_scope);

Diff for: test/Parser/cxx-concept-declaration.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ template<typename T> concept concept bool C6 = true; // expected-warning {{dupli
2525

2626
template<typename T> concept concept bool C7() { return true; } // expected-warning {{duplicate 'concept' declaration specifier}}
2727

28-
concept D1 = true; // expected-error {{C++ requires a type specifier for all declarations}}
29-
30-
template<concept T> concept bool D2 = true; // expected-error {{unknown type name 'T'}}
28+
template<concept T> concept bool D1 = true; // expected-error {{unknown type name 'T'}}

Diff for: test/SemaCXX/cxx-concept-declaration.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ struct B {
1515
struct C {
1616
template<typename T> static concept bool D3 = true; // expected-error {{concept declarations may only appear in namespace scope}}
1717
};
18+
19+
concept bool D4() { return true; } // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
20+
21+
concept bool D5 = true; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}

0 commit comments

Comments
 (0)