diff options
author | Nathan Wilson <nwilson20@gmail.com> | 2016-02-08 05:34:00 +0000 |
---|---|---|
committer | Nathan Wilson <nwilson20@gmail.com> | 2016-02-08 05:34:00 +0000 |
commit | de49845b05d90a2c8dc278850a5d74bf5853f932 (patch) | |
tree | 50156090af63120586326499dd0f80e505aea87a /clang/lib/Sema/SemaDecl.cpp | |
parent | be748c2033b39afbd559166d2209c1c712b896b3 (diff) | |
download | bcm5719-llvm-de49845b05d90a2c8dc278850a5d74bf5853f932.tar.gz bcm5719-llvm-de49845b05d90a2c8dc278850a5d74bf5853f932.zip |
[Concepts] Implement a portion of Concepts TS[dcl.spec.concept]p1 by
diagnosing when 'concept' is specified on a function or template
specialization.
Since a concept can only be applied to a function or variable template,
the concept bit is stored in TemplateDecl as a PointerIntPair.
Reviewers: rsmith, faisalv, aaron.ballman, hubert.reinterpretcast
Differential Revision: http://reviews.llvm.org/D13357
llvm-svn: 260074
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d26e5e18830..c908f672a4f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6002,6 +6002,15 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, NewVD->setInvalidDecl(true); } + // 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 (IsVariableTemplateSpecialization) { + Diag(D.getDeclSpec().getConceptSpecLoc(), + diag::err_concept_specified_specialization) + << (IsPartialSpecialization ? 2 : 1); + } + // C++ Concepts TS [dcl.spec.concept]p6: A variable concept has the // following restrictions: // - The declared type shall have the type bool. @@ -7667,6 +7676,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } if (isConcept) { + // This is a function concept. + if (FunctionTemplateDecl *FTD = NewFD->getDescribedFunctionTemplate()) + FTD->setConcept(); + // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be // applied only to the definition of a function template [...] if (!D.isFunctionDefinition()) { @@ -7733,6 +7746,14 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, << 1 << 3; NewFD->setInvalidDecl(true); } + + // 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 (isFunctionTemplateSpecialization) { + Diag(D.getDeclSpec().getConceptSpecLoc(), + diag::err_concept_specified_specialization) << 1; + } } // If __module_private__ was specified, mark the function accordingly. @@ -7994,9 +8015,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, TemplateId->NumArgs); translateTemplateArguments(TemplateArgsPtr, TemplateArgs); - + HasExplicitTemplateArgs = true; - + if (NewFD->isInvalidDecl()) { HasExplicitTemplateArgs = false; } else if (FunctionTemplate) { |