[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-24 19:27:22
Message-ID: CAMDJ-qYCpwy9qnYDRQtXeoRN6psPRCe4PYHubs4n_qu+D=_KhA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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"


>
> >  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"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul \
24, 2015 at 2:14 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"><div class="HOEnZb"><div class="h5">On Fri, Jul 24, 2015 at \
2:43 PM, Nathan Wilson &lt;<a \
href="mailto:nwilson20@gmail.com">nwilson20@gmail.com</a>&gt; wrote:<br> &gt; nwilson \
created this revision.<br> &gt; nwilson added reviewers: rsmith, faisalv, \
fraggamuffin, hubert.reinterpretcast.<br> &gt; nwilson added a subscriber: \
cfe-commits.<br> &gt;<br>
&gt; Adding diagnostic for concepts declared as non template (function or \
variable)<br> &gt;<br>
&gt; <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11 \
490&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m= \
LAZJ4xieZ12L36iq2xvzWWhNmlrXM-9Zqtcrb9yphUA&s=adpYYwhbIR71SdhHZrX0iqCVe1iJNLTorY4j0petr90&e=" \
rel="noreferrer" target="_blank">http://reviews.llvm.org/D11490</a><br> &gt;<br>
&gt; Files:<br>
&gt;     include/clang/Basic/DiagnosticSemaKinds.td<br>
&gt;     lib/Sema/SemaDecl.cpp<br>
&gt;     test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt;<br>
&gt; Index: test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt; ===================================================================<br>
&gt; --- test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt; +++ test/SemaCXX/cxx-concept-declaration.cpp<br>
&gt; @@ -15,3 +15,7 @@<br>
&gt;   struct C {<br>
&gt;      template&lt;typename T&gt; static concept bool D3 = true; // expected-error \
{{concept declarations may only appear in namespace scope}}<br> &gt;   };<br>
&gt; +<br>
&gt; +concept bool D4() { return true; } // expected-error {{concept can only be \
applied to a function or variable template definition}}<br> &gt; +<br>
&gt; +concept bool D5 = true; // expected-error {{concept can only be applied to a \
function or variable template definition}}<br> &gt; Index: lib/Sema/SemaDecl.cpp<br>
&gt; ===================================================================<br>
&gt; --- lib/Sema/SemaDecl.cpp<br>
&gt; +++ lib/Sema/SemaDecl.cpp<br>
&gt; @@ -4865,6 +4865,12 @@<br>
&gt;         // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall \
be<br> &gt;         // applied only to the definition of a function template or \
variable<br> &gt;         // template, declared in namespace scope<br>
&gt; +      if (!TemplateParamLists.size()) {<br>
&gt; +         Diag(D.getDeclSpec().getConceptSpecLoc(),<br>
&gt; +                 diag::err_concept_decl_non_template);<br>
&gt; +         return nullptr;<br>
&gt; +      }<br>
&gt; +<br>
&gt;         if (!DC-&gt;getRedeclContext()-&gt;isFileContext()) {<br>
&gt;            Diag(D.getIdentifierLoc(),<br>
&gt;                    \
diag::err_concept_decls_may_only_appear_in_namespace_scope);<br> &gt; Index: \
include/clang/Basic/DiagnosticSemaKinds.td<br> &gt; \
===================================================================<br> &gt; --- \
include/clang/Basic/DiagnosticSemaKinds.td<br> &gt; +++ \
include/clang/Basic/DiagnosticSemaKinds.td<br> &gt; @@ -1966,6 +1966,8 @@<br>
&gt;      &quot;use __attribute__((visibility(\&quot;hidden\&quot;))) attribute \
instead&quot;&gt;;<br> &gt;<br>
&gt;   // C++ Concepts TS<br>
&gt; +def err_concept_decl_non_template : Error&lt;<br>
&gt; +   &quot;concept can only be applied to a function or variable template \
definition&quot;&gt;;<br> <br>
</div></div>Since we are using &quot;concept&quot; as a grammar term, I think we want \
to<br> quote it. Similar diagnostics suggest phrasing like:<br>
<br>
&quot;&#39;concept&#39; can only appear on a function template or variable \
template<br> definition&quot;<br>
<br>
This also reduces some ambiguity over how &quot;function or variable template&quot; \
binds.<br> <br>
~Aaron<br></blockquote><div><br></div><div>May we apply both this suggestion and \
Hubert&#39;s? So it would be:</div><div><br></div><div><span \
style="font-size:12.8000001907349px">&quot;the &#39;concept&#39; specifier may only \
be applied to the definition of a function or variable template&quot;</span><br \
style="font-size:12.8000001907349px"></div><div>  </div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <span class=""><br>
&gt;   def err_concept_decls_may_only_appear_in_namespace_scope : Error&lt;<br>
&gt;      &quot;concept declarations may only appear in namespace \
scope&quot;&gt;;<br> &gt;   def err_function_concept_not_defined : Error&lt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</span>&gt; _______________________________________________<br>
&gt; cfe-commits mailing list<br>
&gt; <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
&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;<br> </blockquote></div><br></div></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