]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: explicit() ignored on deduction guide [PR100065]
authorMarek Polacek <polacek@redhat.com>
Mon, 7 Jun 2021 20:06:00 +0000 (16:06 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 8 Jun 2021 22:29:32 +0000 (18:29 -0400)
When we have explicit() with a value-dependent argument, we can't
evaluate it at parsing time, so cp_parser_function_specifier_opt stashes
the argument into the decl-specifiers and grokdeclarator then stores it
into explicit_specifier_map, which is then used when substituting the
function decl.  grokdeclarator stores it for constructors and conversion
functions, but we also need to do it for deduction guides, otherwise
we'll forget that we've seen an explicit-specifier as in the attached
test.

PR c++/100065

gcc/cp/ChangeLog:

* decl.c (grokdeclarator): Store a value-dependent
explicit-specifier even for deduction guides.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/explicit18.C: New test.

gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp2a/explicit18.C [new file with mode: 0644]

index a3687dbb0dd0ed6e7279eda4798bd34a26703f1b..cbf647dd5697a4705505fd3c0b595b8f55e3ef6e 100644 (file)
@@ -14043,6 +14043,8 @@ grokdeclarator (const cp_declarator *declarator,
                storage_class = sc_none;
              }
          }
+       if (declspecs->explicit_specifier)
+         store_explicit_specifier (decl, declspecs->explicit_specifier);
       }
     else
       {
diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit18.C b/gcc/testsuite/g++.dg/cpp2a/explicit18.C
new file mode 100644 (file)
index 0000000..c8916fa
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/100065
+// { dg-do compile { target c++20 } }
+
+template<bool B>
+struct bool_constant {
+  static constexpr bool value = B;
+  constexpr operator bool() const { return value; }
+};
+
+using true_type = bool_constant<true>;
+using false_type = bool_constant<false>;
+
+template<bool>
+struct X {
+    template<typename T>
+    X(T);
+};
+
+template<bool b>
+explicit(b) X(bool_constant<b>) -> X<b>;
+
+X false_ = false_type{}; // OK
+X true_  = true_type{};  // { dg-error "explicit deduction guide" }