]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: member alias declaration [PR103968]
authorJason Merrill <jason@redhat.com>
Sun, 27 Mar 2022 04:28:30 +0000 (00:28 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 28 Mar 2022 13:35:58 +0000 (09:35 -0400)
Here, we were wrongly thinking that (const Options&)Widget<T>::c_options is
not value-dependent because neither the type nor the (value of) c_options
are dependent, but since we're binding it to a reference we also need to
consider that it has a value-dependent address.

PR c++/103968

gcc/cp/ChangeLog:

* pt.cc (value_dependent_expression_p): Check
has_value_dependent_address for conversion to reference.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/alias-decl-mem1.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C [new file with mode: 0644]

index b229c9fc739ffeace7ddabc52f842c685354b895..41f1ef1f64d9e12e20c997794aacb0a988a33513 100644 (file)
@@ -27449,6 +27449,10 @@ value_dependent_expression_p (tree expression)
        if (TREE_CODE (expression) == TREE_LIST)
          return any_value_dependent_elements_p (expression);
 
+       if (TREE_CODE (type) == REFERENCE_TYPE
+           && has_value_dependent_address (expression))
+         return true;
+
        return value_dependent_expression_p (expression);
       }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-mem1.C
new file mode 100644 (file)
index 0000000..3e422de
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/103968
+// { dg-do compile { target c++11 } }
+
+template <typename Opt, Opt const& options>
+struct trait
+{
+    template <typename T>
+    struct NonInstantiated{};
+};
+
+struct Options {};
+
+template <typename T>
+struct Widget
+{
+    static constexpr auto c_options = Options{};
+    using Trait = trait<decltype(c_options), c_options>;
+};
+
+Widget<int>::Trait b{}; // Crashes GCC > 10.3