[PATCH] D11916: [CONCEPTS] Add diagnostic; invalid tag when concept specified

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 12 11:28:15 PDT 2015


LGTM!

~Aaron

On Wed, Aug 12, 2015 at 1:40 PM, Nathan Wilson <nwilson20 at gmail.com> wrote:
> nwilson updated this revision to Diff 31957.
> nwilson added a comment.
>
> Addressing comments which were discussed on the mailing list - Apply the same text when diagnosing a free standing declaration as suggested by Aaron. Replace diagnostic identifier err_concept_decl_non_template with err_concept_wrong_decl_kind as suggested by Hubert and Richard.  Fix tests corresponding to the changes.
>
>
> http://reviews.llvm.org/D11916
>
> Files:
>   include/clang/Basic/DiagnosticSemaKinds.td
>   lib/Sema/SemaDecl.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
> @@ -23,3 +23,13 @@
>  template<typename T>
>  concept bool D6; // expected-error {{variable concept declaration must be initialized}}
>
> +// Tag
> +concept class CC1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +concept struct CS1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +concept union CU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +concept enum CE1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +template <typename T> concept class TCC1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +template <typename T> concept struct TCS1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +template <typename T> concept union TCU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> +
> +concept bool; // expected-error {{'concept' can only appear on the definition of a function template or variable template}}
> Index: lib/Sema/SemaDecl.cpp
> ===================================================================
> --- lib/Sema/SemaDecl.cpp
> +++ lib/Sema/SemaDecl.cpp
> @@ -3662,6 +3662,14 @@
>      return TagD;
>    }
>
> +  if (DS.isConceptSpecified()) {
> +    // C++ Concepts TS [dcl.spec.concept]p1: A concept definition refers to
> +    // either a function concept and its definition or a variable concept and
> +    // its initializer.
> +    Diag(DS.getConceptSpecLoc(), diag::err_concept_wrong_decl_kind);
> +    return TagD;
> +  }
> +
>    DiagnoseFunctionSpecifiers(DS);
>
>    if (DS.isFriendSpecified()) {
> @@ -4865,7 +4873,7 @@
>      // template, declared in namespace scope
>      if (!TemplateParamLists.size()) {
>        Diag(D.getDeclSpec().getConceptSpecLoc(),
> -           diag::err_concept_decl_non_template);
> +           diag:: err_concept_wrong_decl_kind);
>        return nullptr;
>      }
>
> Index: include/clang/Basic/DiagnosticSemaKinds.td
> ===================================================================
> --- include/clang/Basic/DiagnosticSemaKinds.td
> +++ include/clang/Basic/DiagnosticSemaKinds.td
> @@ -1965,7 +1965,7 @@
>    "use __attribute__((visibility(\"hidden\"))) attribute instead">;
>
>  // C++ Concepts TS
> -def err_concept_decl_non_template : Error<
> +def err_concept_wrong_decl_kind : 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">;
>
>


More information about the cfe-commits mailing list