On Fri, Oct 13, 2017 at 1:21 PM, Markus Trippelsdorf
<mar...@trippelsdorf.de> wrote:
> On 2017.10.13 at 12:02 -0400, Jason Merrill wrote:
>> On Fri, Oct 13, 2017 at 5:40 AM, Markus Trippelsdorf
>> <mar...@trippelsdorf.de> wrote:
>> > r253266 introduced a bogus "cannot bind bitfield" error that breaks
>> > building Chromium and Node.js.
>> > Fix by removing the ugly goto.
>> >
>> > Tested on ppc64le.
>> > Ok for trunk?
>>
>> No, this just undoes my change, so we go back to not doing type
>> checking for non-dependent static casts.  Better I think to avoid the
>> call to build_static_cast in the first place, by teaching
>> stabilize_reference that it can return a NON_DEPENDENT_EXPR unchanged.
>> How does this (untested) patch work for you?
>
> It works fine. Thanks.
> It would be good to have a testcase that checks the type checking for
> non-dependent static casts.
> I'll let you handle the current issue.

Done.
commit d570081ae5d9afd421acccb10eef82baab2b35da
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Oct 13 12:31:21 2017 -0400

            PR c++/82357 - bit-field in template
    
            * tree.c (cp_stabilize_reference): Just return a NON_DEPENDENT_EXPR.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index e21ff6a1572..366f46f1506 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -333,6 +333,10 @@ cp_stabilize_reference (tree ref)
 {
   switch (TREE_CODE (ref))
     {
+    case NON_DEPENDENT_EXPR:
+      /* We aren't actually evaluating this.  */
+      return ref;
+
     /* We need to treat specially anything stabilize_reference doesn't
        handle specifically.  */
     case VAR_DECL:
diff --git a/gcc/testsuite/g++.dg/template/bitfield4.C 
b/gcc/testsuite/g++.dg/template/bitfield4.C
new file mode 100644
index 00000000000..4927b7ab144
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/bitfield4.C
@@ -0,0 +1,6 @@
+// PR c++/82357
+
+template <typename> struct A {
+  A() { x |= 0; }
+  int x : 8;
+};
diff --git a/gcc/testsuite/g++.dg/template/cast4.C 
b/gcc/testsuite/g++.dg/template/cast4.C
new file mode 100644
index 00000000000..2f46c7189eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/cast4.C
@@ -0,0 +1,4 @@
+template <class T> void f()
+{
+  static_cast<int&>(42);       // { dg-error "static_cast" }
+}

Reply via email to