[PATCH] D11490: [Concepts] Add diagnostic: non template declaration

Aaron Ballman aaron at aaronballman.com
Fri Jul 24 12:43:45 PDT 2015


On Fri, Jul 24, 2015 at 3:43 PM, Hubert Tong
<hubert.reinterpretcast at gmail.com> wrote:
> Thanks Aaron for copying the similar messages here. I'd still like the use
> "definition of", but with Aaron's suggestion as the base.
> I considered using plural nouns instead of singular ones to match the
> existing messages better, but the result was clunky.
>
> "'concept' can only appear on the definition of a function template or
> variable template"

Perfect!

~Aaron

>
> On Fri, Jul 24, 2015 at 3:37 PM, Aaron Ballman <aaron at aaronballman.com>
> wrote:
>>
>> On Fri, Jul 24, 2015 at 3:27 PM, Nathan Wilson <nwilson20 at gmail.com>
>> wrote:
>> >
>> >
>> > On Fri, Jul 24, 2015 at 2:14 PM, Aaron Ballman <aaron at aaronballman.com>
>> > wrote:
>> >>
>> >> On Fri, Jul 24, 2015 at 2:43 PM, Nathan Wilson <nwilson20 at gmail.com>
>> >> wrote:
>> >> > nwilson created this revision.
>> >> > nwilson added reviewers: rsmith, faisalv, fraggamuffin,
>> >> > hubert.reinterpretcast.
>> >> > nwilson added a subscriber: cfe-commits.
>> >> >
>> >> > Adding diagnostic for concepts declared as non template (function or
>> >> > variable)
>> >> >
>> >> > http://reviews.llvm.org/D11490
>> >>
>> >> >
>> >> > 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
>> >> > @@ -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
>> >> > be applied to a function or variable template definition}}
>> >> > +
>> >> > +concept bool D5 = true; // expected-error {{concept can only be
>> >> > applied
>> >> > to a function or variable template definition}}
>> >> > 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 be applied to a function or variable template
>> >> > definition">;
>> >>
>> >> Since we are using "concept" as a grammar term, I think we want to
>> >> quote it. Similar diagnostics suggest phrasing like:
>> >>
>> >> "'concept' can only appear on a function template or variable template
>> >> definition"
>> >>
>> >> This also reduces some ambiguity over how "function or variable
>> >> template"
>> >> binds.
>> >>
>> >> ~Aaron
>> >
>> >
>> > May we apply both this suggestion and Hubert's? So it would be:
>> >
>> > "the 'concept' specifier may only be applied to the definition of a
>> > function
>> > or variable template"
>>
>> I don't have a strong preference, but I think "specifier may only be"
>> is kind of wordy without adding much value. For comparison:
>>
>> def err_inline_non_function : Error<
>>   "'inline' can only appear on functions">;
>> def err_noreturn_non_function : Error<
>>   "'_Noreturn' can only appear on functions">;
>> def err_virtual_non_function : Error<
>>   "'virtual' can only appear on non-static member functions">;
>> def err_explicit_non_function : Error<
>>   "'explicit' can only appear on non-static member functions">;
>>
>> ~Aaron
>>
>> >
>> >>
>> >>
>> >> >  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 at cs.uiuc.edu
>> >> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> >> >
>> >
>> >
>
>



More information about the cfe-commits mailing list