[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: Re: [PATCH] D11490: [Concepts] Add diagnostic: non template declaration
From: Nathan Wilson <nwilson20 () gmail ! com>
Date: 2015-07-30 4:21:18
Message-ID: 8e3cb3eec5889cac141e9385631973b5 () localhost ! localdomain
[Download RAW message or body]
nwilson updated this revision to Diff 30984.
nwilson added a comment.
Removing failing test case (in Parser) created by this Patch
http://reviews.llvm.org/D11490
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Parser/cxx-concept-declaration.cpp
test/SemaCXX/cxx-concept-declaration.cpp
Index: test/SemaCXX/cxx-concept-declaration.cpp
===================================================================
--- test/SemaCXX/cxx-concept-declaration.cpp
+++ test/SemaCXX/cxx-concept-declaration.cpp
@@ -15,3 +15,7 @@
struct C {
template<typename T> static concept bool D3 = true; // expected-error {{concept \
declarations may only appear in namespace scope}} };
+
+concept bool D4() { return true; } // expected-error {{'concept' can only appear on \
the definition of a function template or variable template}} +
+concept bool D5 = true; // expected-error {{'concept' can only appear on the \
definition of a function template or variable template}}
Index: test/Parser/cxx-concept-declaration.cpp
===================================================================
--- test/Parser/cxx-concept-declaration.cpp
+++ test/Parser/cxx-concept-declaration.cpp
@@ -25,6 +25,4 @@
template<typename T> concept concept bool C7() { return true; } // expected-warning \
{{duplicate 'concept' declaration specifier}}
-concept D1 = true; // expected-error {{C++ requires a type specifier for all \
declarations}}
-
-template<concept T> concept bool D2 = true; // expected-error {{unknown type name \
'T'}} +template<concept T> concept bool D1 = true; // expected-error {{unknown type \
name 'T'}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -4865,6 +4865,12 @@
// C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
// applied only to the definition of a function template or variable
// template, declared in namespace scope
+ if (!TemplateParamLists.size()) {
+ Diag(D.getDeclSpec().getConceptSpecLoc(),
+ diag::err_concept_decl_non_template);
+ return nullptr;
+ }
+
if (!DC->getRedeclContext()->isFileContext()) {
Diag(D.getIdentifierLoc(),
diag::err_concept_decls_may_only_appear_in_namespace_scope);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1966,6 +1966,8 @@
"use __attribute__((visibility(\"hidden\"))) attribute instead">;
// C++ Concepts TS
+def err_concept_decl_non_template : Error<
+ "'concept' can only appear on the definition of a function template or variable \
template">; def err_concept_decls_may_only_appear_in_namespace_scope : Error<
"concept declarations may only appear in namespace scope">;
def err_function_concept_not_defined : Error<
["D11490.30984.patch" (text/x-patch)]
Index: test/SemaCXX/cxx-concept-declaration.cpp
===================================================================
--- test/SemaCXX/cxx-concept-declaration.cpp
+++ test/SemaCXX/cxx-concept-declaration.cpp
@@ -15,3 +15,7 @@
struct C {
template<typename T> static concept bool D3 = true; // expected-error {{concept \
declarations may only appear in namespace scope}} };
+
+concept bool D4() { return true; } // expected-error {{'concept' can only appear on \
the definition of a function template or variable template}} +
+concept bool D5 = true; // expected-error {{'concept' can only appear on the \
definition of a function template or variable template}}
Index: test/Parser/cxx-concept-declaration.cpp
===================================================================
--- test/Parser/cxx-concept-declaration.cpp
+++ test/Parser/cxx-concept-declaration.cpp
@@ -25,6 +25,4 @@
template<typename T> concept concept bool C7() { return true; } // expected-warning \
{{duplicate 'concept' declaration specifier}}
-concept D1 = true; // expected-error {{C++ requires a type specifier for all \
declarations}}
-
-template<concept T> concept bool D2 = true; // expected-error {{unknown type name \
'T'}} +template<concept T> concept bool D1 = true; // expected-error {{unknown type \
name 'T'}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -4865,6 +4865,12 @@
// C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be
// applied only to the definition of a function template or variable
// template, declared in namespace scope
+ if (!TemplateParamLists.size()) {
+ Diag(D.getDeclSpec().getConceptSpecLoc(),
+ diag::err_concept_decl_non_template);
+ return nullptr;
+ }
+
if (!DC->getRedeclContext()->isFileContext()) {
Diag(D.getIdentifierLoc(),
diag::err_concept_decls_may_only_appear_in_namespace_scope);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1966,6 +1966,8 @@
"use __attribute__((visibility(\"hidden\"))) attribute instead">;
// C++ Concepts TS
+def err_concept_decl_non_template : Error<
+ "'concept' can only appear on the definition of a function template or variable \
template">; def err_concept_decls_may_only_appear_in_namespace_scope : Error<
"concept declarations may only appear in namespace scope">;
def err_function_concept_not_defined : Error<
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic