[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:       Hubert Tong <hubert.reinterpretcast () gmail ! com>
Date:       2015-07-24 19:43:09
Message-ID: CACvkUqZC+rsE6VhYdBQMRGfchcpueFLYz7GKtaw+=yHzuksDJw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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"

On Fri, Jul 24, 2015 at 3:37 PM, Aaron Ballman <aaron@aaronballman.com>
wrote:

> On Fri, Jul 24, 2015 at 3:27 PM, Nathan Wilson <nwilson20@gmail.com>
> wrote:
> >
> >
> > On Fri, Jul 24, 2015 at 2:14 PM, Aaron Ballman <aaron@aaronballman.com>
> > wrote:
> >>
> >> On Fri, Jul 24, 2015 at 2:43 PM, Nathan Wilson <nwilson20@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@cs.uiuc.edu
> >> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >> >
> >
> >
>

[Attachment #5 (text/html)]

<div dir="ltr"><div>Thanks Aaron for copying the similar messages here. I&#39;d still \
like the use &quot;definition of&quot;, but with Aaron&#39;s suggestion as the \
base.<br></div>I considered using plural nouns instead of singular ones to match the \
existing messages better, but the result was \
clunky.<br><div><br>&quot;&#39;concept&#39; can only appear on the definition of a \
function template or variable template&quot;<br></div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 24, 2015 at 3:37 PM, \
Aaron Ballman <span dir="ltr">&lt;<a href="mailto:aaron@aaronballman.com" \
target="_blank">aaron@aaronballman.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">On Fri, Jul 24, 2015 at 3:27 PM, Nathan Wilson &lt;<a \
href="mailto:nwilson20@gmail.com">nwilson20@gmail.com</a>&gt; wrote:<br> &gt;<br>
&gt;<br>
&gt; On Fri, Jul 24, 2015 at 2:14 PM, Aaron Ballman &lt;<a \
href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>&gt;<br> &gt; \
wrote:<br> &gt;&gt;<br>
&gt;&gt; On Fri, Jul 24, 2015 at 2:43 PM, Nathan Wilson &lt;<a \
href="mailto:nwilson20@gmail.com">nwilson20@gmail.com</a>&gt;<br> <span \
class="">&gt;&gt; wrote:<br> &gt;&gt; &gt; nwilson created this revision.<br>
&gt;&gt; &gt; nwilson added reviewers: rsmith, faisalv, fraggamuffin,<br>
&gt;&gt; &gt; hubert.reinterpretcast.<br>
&gt;&gt; &gt; nwilson added a subscriber: cfe-commits.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Adding diagnostic for concepts declared as non template (function \
or<br> &gt;&gt; &gt; variable)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llv \
m.org_D11490&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREe \
q0cCxk&m=Cy8MzNPK3FdAX67YBDWB2xoWCEPICZ9_MIkvhLBsvl4&s=tBY56OYkhlr2nwDVntH13bYNysNq6HIrso27A1MbWo8&e=" \
rel="noreferrer" target="_blank">http://reviews.llvm.org/D11490</a><br> &gt;&gt;<br>
&gt;&gt; &gt;<br>
</span><div><div class="h5">&gt;&gt; &gt; Files:<br>
&gt;&gt; &gt;     include/clang/Basic/DiagnosticSemaKinds.td<br>
&gt;&gt; &gt;     lib/Sema/SemaDecl.cpp<br>
&gt;&gt; &gt;     test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Index: test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt;&gt; &gt; ===================================================================<br>
&gt;&gt; &gt; --- test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt;&gt; &gt; +++ test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt;&gt; &gt; @@ -15,3 +15,7 @@<br>
&gt;&gt; &gt;   struct C {<br>
&gt;&gt; &gt;      template&lt;typename T&gt; static concept bool D3 = true; // \
expected-error<br> &gt;&gt; &gt; {{concept declarations may only appear in namespace \
scope}}<br> &gt;&gt; &gt;   };<br>
&gt;&gt; &gt; +<br>
&gt;&gt; &gt; +concept bool D4() { return true; } // expected-error {{concept can \
only<br> &gt;&gt; &gt; be applied to a function or variable template definition}}<br>
&gt;&gt; &gt; +<br>
&gt;&gt; &gt; +concept bool D5 = true; // expected-error {{concept can only be \
applied<br> &gt;&gt; &gt; to a function or variable template definition}}<br>
&gt;&gt; &gt; Index: lib/Sema/SemaDecl.cpp<br>
&gt;&gt; &gt; ===================================================================<br>
&gt;&gt; &gt; --- lib/Sema/SemaDecl.cpp<br>
&gt;&gt; &gt; +++ lib/Sema/SemaDecl.cpp<br>
&gt;&gt; &gt; @@ -4865,6 +4865,12 @@<br>
&gt;&gt; &gt;         // C++ Concepts TS [dcl.spec.concept]p1: The concept \
specifier<br> &gt;&gt; &gt; shall be<br>
&gt;&gt; &gt;         // applied only to the definition of a function template or<br>
&gt;&gt; &gt; variable<br>
&gt;&gt; &gt;         // template, declared in namespace scope<br>
&gt;&gt; &gt; +      if (!TemplateParamLists.size()) {<br>
&gt;&gt; &gt; +         Diag(D.getDeclSpec().getConceptSpecLoc(),<br>
&gt;&gt; &gt; +                 diag::err_concept_decl_non_template);<br>
&gt;&gt; &gt; +         return nullptr;<br>
&gt;&gt; &gt; +      }<br>
&gt;&gt; &gt; +<br>
&gt;&gt; &gt;         if (!DC-&gt;getRedeclContext()-&gt;isFileContext()) {<br>
&gt;&gt; &gt;            Diag(D.getIdentifierLoc(),<br>
&gt;&gt; &gt;                    \
diag::err_concept_decls_may_only_appear_in_namespace_scope);<br> &gt;&gt; &gt; Index: \
include/clang/Basic/DiagnosticSemaKinds.td<br> &gt;&gt; &gt; \
===================================================================<br> &gt;&gt; &gt; \
--- include/clang/Basic/DiagnosticSemaKinds.td<br> &gt;&gt; &gt; +++ \
include/clang/Basic/DiagnosticSemaKinds.td<br> &gt;&gt; &gt; @@ -1966,6 +1966,8 \
@@<br> &gt;&gt; &gt;      &quot;use __attribute__((visibility(\&quot;hidden\&quot;))) \
attribute instead&quot;&gt;;<br> &gt;&gt; &gt;<br>
&gt;&gt; &gt;   // C++ Concepts TS<br>
&gt;&gt; &gt; +def err_concept_decl_non_template : Error&lt;<br>
&gt;&gt; &gt; +   &quot;concept can only be applied to a function or variable \
template<br> &gt;&gt; &gt; definition&quot;&gt;;<br>
&gt;&gt;<br>
&gt;&gt; Since we are using &quot;concept&quot; as a grammar term, I think we want \
to<br> &gt;&gt; quote it. Similar diagnostics suggest phrasing like:<br>
&gt;&gt;<br>
&gt;&gt; &quot;&#39;concept&#39; can only appear on a function template or variable \
template<br> &gt;&gt; definition&quot;<br>
&gt;&gt;<br>
&gt;&gt; This also reduces some ambiguity over how &quot;function or variable \
template&quot;<br> &gt;&gt; binds.<br>
&gt;&gt;<br>
&gt;&gt; ~Aaron<br>
&gt;<br>
&gt;<br>
&gt; May we apply both this suggestion and Hubert&#39;s? So it would be:<br>
&gt;<br>
&gt; &quot;the &#39;concept&#39; specifier may only be applied to the definition of a \
function<br> &gt; or variable template&quot;<br>
<br>
</div></div>I don&#39;t have a strong preference, but I think &quot;specifier may \
only be&quot;<br> is kind of wordy without adding much value. For comparison:<br>
<br>
def err_inline_non_function : Error&lt;<br>
   &quot;&#39;inline&#39; can only appear on functions&quot;&gt;;<br>
def err_noreturn_non_function : Error&lt;<br>
   &quot;&#39;_Noreturn&#39; can only appear on functions&quot;&gt;;<br>
def err_virtual_non_function : Error&lt;<br>
   &quot;&#39;virtual&#39; can only appear on non-static member \
functions&quot;&gt;;<br> def err_explicit_non_function : Error&lt;<br>
   &quot;&#39;explicit&#39; can only appear on non-static member \
functions&quot;&gt;;<br> <br>
~Aaron<br>
<span class=""><br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; &gt;   def err_concept_decls_may_only_appear_in_namespace_scope : \
Error&lt;<br> &gt;&gt; &gt;      &quot;concept declarations may only appear in \
namespace scope&quot;&gt;;<br> &gt;&gt; &gt;   def err_function_concept_not_defined : \
Error&lt;<br> &gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; cfe-commits mailing list<br>
</span>&gt;&gt; &gt; <a \
href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br> &gt;&gt; &gt; \
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" rel="noreferrer" \
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br> \
&gt;&gt; &gt;<br> &gt;<br>
&gt;<br>
</blockquote></div><br></div>



_______________________________________________
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