<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 22, 2013 at 4:03 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div class="im">On Tue, Oct 22, 2013 at 3:43 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>On Tue, Oct 22, 2013 at 2:56 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>

</div><div class="gmail_extra"><div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: majnemer<br>
Date: Tue Oct 22 16:56:38 2013<br>
New Revision: 193203<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=193203&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=193203&view=rev</a><br>
Log:<br>
Sema: Allow IndirectFieldDecl to appear in a non-type template argument<br>
<br>
We would not identify pointer-to-member construction in a non-type<br>
template argument if it was either a FieldDecl or a CXXMethodDecl.<br>
However, this would incorrectly reject declarations that were injected<br>
via an IndirectFieldDecl (e.g. a field inside of an anonymous union).<br></blockquote><div><br></div></div><div>Is this really correct? Such fields are not members of the enclosing non-anonymous struct. &Z::union_member below should have type "int Z::<anonymous union>::*", not "int Z::*", as far as I can tell.</div>

</div></div></div></blockquote><div><br></div></div><div>GCC, EDG and MSVC all seem to think it should be allowed.</div><div><br></div><div>Note that we allowed the following related test case before my change:</div><div>
<div>struct a {</div>
<div>  union { int i; };</div><div>};</div><div><br></div><div>template <int (a::*)> struct b;</div><div>constexpr auto z = &a::i;</div><div>typedef b<z> c;</div></div><div><br></div><div>Do you consider this ill-formed as well? </div>
<div><div class="h5">
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">

<div><div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
This fixes PR17657.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaTemplate.cpp<br>
    cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=193203&r1=193202&r2=193203&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=193203&r1=193202&r2=193203&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Oct 22 16:56:38 2013<br>
@@ -4609,8 +4609,11 @@ static bool CheckTemplateArgumentPointer<br>
                   diag::err_template_arg_not_pointer_to_member_form)<br>
       << Arg->getSourceRange();<br>
<br>
-  if (isa<FieldDecl>(DRE->getDecl()) || isa<CXXMethodDecl>(DRE->getDecl())) {<br>
+  if (isa<FieldDecl>(DRE->getDecl()) ||<br>
+      isa<IndirectFieldDecl>(DRE->getDecl()) ||<br>
+      isa<CXXMethodDecl>(DRE->getDecl())) {<br>
     assert((isa<FieldDecl>(DRE->getDecl()) ||<br>
+            isa<IndirectFieldDecl>(DRE->getDecl()) ||<br>
             !cast<CXXMethodDecl>(DRE->getDecl())->isStatic()) &&<br>
            "Only non-static member pointers can make it here");<br>
<br>
<br>
Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=193203&r1=193202&r2=193203&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=193203&r1=193202&r2=193203&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp (original)<br>
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp Tue Oct 22 16:56:38 2013<br>
@@ -75,6 +75,9 @@ struct Z {<br>
<br>
   int int_member;<br>
   float float_member;<br>
+  union {<br>
+    int union_member;<br>
+  };<br>
 };<br>
 template<int (Z::*pmf)(int)> struct A6; // expected-note{{template parameter is declared here}}<br>
 A6<&Z::foo> *a17_1;<br>
@@ -88,6 +91,7 @@ A7<&Z::int_member> *a18_1;<br>
 A7c<&Z::int_member> *a18_2;<br>
 A7<&Z::float_member> *a18_3; // expected-error{{non-type template argument of type 'float Z::*' cannot be converted to a value of type 'int Z::*'}}<br>
 A7c<(&Z::int_member)> *a18_4; // expected-warning{{address non-type template argument cannot be surrounded by parentheses}}<br>
+A7c<&Z::union_member> *a18_5;<br></blockquote><div><br></div></div></div><div>Can we mangle this?</div></div></div></div></blockquote><div><br></div></div></div><div>We can't mangle it yet but there is no reason to see why we couldn't. EDG and GCC both disagree on what it should be mangled to. EDG sticks in __Cn where n corresponds to the depth of the anonymous unions if they are nested, GCC mangles it as {unnamed type#1}.  I believe neither are correct, the Itanium ABI 5.1.2 General Structure section states that the name of an anonymous union comes from "the first named data member found by a pre-order, depth-first, declaration-order walk of the data members of the anonymous union".</div>
</div></div></div></blockquote><div><br></div><div>We now mangle it in r193269.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">

<div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
 template<unsigned char C> struct Overflow; // expected-note{{template parameter is declared here}}<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div><br></div></div>
</blockquote></div></div><br></div></div>
</blockquote></div><br></div></div>