From: Marek Polacek Date: Mon, 7 Jun 2021 20:06:00 +0000 (-0400) Subject: c++: explicit() ignored on deduction guide [PR100065] X-Git-Tag: releases/gcc-11.2.0~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a9d8fd580d6afab669bae68e116e2135c2a8670;p=thirdparty%2Fgcc.git c++: explicit() ignored on deduction guide [PR100065] 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. (cherry picked from commit 1afa4facb9348cac0349ff9c30066aa25a3608f7) --- diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8908308ec708..d2fc1c1d4a30 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -13991,6 +13991,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 index 000000000000..c8916fa4743b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/explicit18.C @@ -0,0 +1,23 @@ +// PR c++/100065 +// { dg-do compile { target c++20 } } + +template +struct bool_constant { + static constexpr bool value = B; + constexpr operator bool() const { return value; } +}; + +using true_type = bool_constant; +using false_type = bool_constant; + +template +struct X { + template + X(T); +}; + +template +explicit(b) X(bool_constant) -> X; + +X false_ = false_type{}; // OK +X true_ = true_type{}; // { dg-error "explicit deduction guide" }