The following patch attempts to implement CWG1670 and related LWG4468.
2025-11-19 Jakub Jelinek <jakub@redhat.com>
gcc/cp/
* parser.cc (cp_parser_conversion_type_id): Implement C++ DR1670
- auto as conversion-type-id. Pedwarn on conversion operators
with placeholder return type.
gcc/testsuite/
* g++.dg/DRs/dr1670-1.C: New test.
* g++.dg/DRs/dr1670-2.C: New test.
* g++.dg/DRs/dr1670-3.C: New test.
* g++.dg/modules/auto-1_a.H: Use dg-options instead of
dg-additional-options.
* g++.dg/modules/auto-1_b.C: Likewise.
* g++.dg/cpp1y/auto-fn12.C: Likewise.
* g++.dg/cpp1y/auto-fn13.C: Add empty dg-options.
* g++.dg/cpp1y/auto-fn22.C: Likewise.
* g++.dg/cpp1y/constexpr-assert2.C: Likewise.
* g++.dg/cpp1y/auto-fn44.C: Add dg-options -Wpedantic and expect
further warnings.
* g++.dg/cpp1y/auto-fn50.C: Likewise.
* g++.dg/cpp0x/auto9.C: Expect two errors always rather than just
for C++11.
libstdc++-v3/
* include/std/type_traits (constant_wrapper conversion operator):
Use decltype(value) instead of decltype(auto). Resolves LWG4468.
error ("invalid use of %<auto%> in conversion operator");
return error_mark_node;
}
- else if (template_parm_scope_p ())
- warning (0, "use of %<auto%> in member template "
- "conversion operator can never be deduced");
+ else
+ {
+ pedwarn (input_location, OPT_Wpedantic,
+ "invalid use of %<auto%> in conversion operator");
+ if (template_parm_scope_p ())
+ warning (0, "use of %<auto%> in member template "
+ "conversion operator can never be deduced");
+ }
}
return type_specified;
--- /dev/null
+// DR 1670 - auto as conversion-type-id
+// { dg-do compile { target c++14 } }
+
+struct S {
+ operator auto () { return 0; } // { dg-error "invalid use of 'auto' in conversion operator" }
+};
+struct T {
+ operator decltype (auto) () { return 0; } // { dg-error "invalid use of 'auto' in conversion operator" }
+};
--- /dev/null
+// DR 1670 - auto as conversion-type-id
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wpedantic" }
+
+struct S {
+ operator auto () { return 0; } // { dg-warning "invalid use of 'auto' in conversion operator" }
+};
+struct T {
+ operator decltype (auto) () { return 0; } // { dg-warning "invalid use of 'auto' in conversion operator" }
+};
--- /dev/null
+// DR 1670 - auto as conversion-type-id
+// { dg-do compile { target c++14 } }
+// { dg-options "" }
+
+struct S {
+ operator auto () { return 0; }
+};
+struct T {
+ operator decltype (auto) () { return 0; }
+};
struct A
{
- operator auto (); // { dg-error "auto" "" { target { ! c++14 } } }
- operator auto *(); // { dg-error "auto" "" { target { ! c++14 } } }
+ operator auto (); // { dg-error "auto" }
+ operator auto *(); // { dg-error "auto" }
};
struct A2
// { dg-do compile { target c++14 } }
// { dg-final { scan-assembler "_ZN1AIiEcvDaEv" } }
-// { dg-additional-options -fno-implicit-constexpr }
+// { dg-options -fno-implicit-constexpr }
template <class T>
struct A {
// { dg-do compile { target c++14 } }
+// { dg-options "" }
struct A {
template <class T>
// { dg-do compile { target c++14 } }
+// { dg-options "" }
struct A
{
// PR c++/79474
// { dg-do compile { target c++14 } }
+// { dg-options "-Wpedantic" }
struct Funject
{
- operator auto() { return +[](bool b) {return b;}; }
+ operator auto() { return +[](bool b) {return b;}; } // { dg-warning "invalid use of 'auto' in conversion operator" }
operator auto() { return +[](bool b, bool, bool) {return b;}; } // { dg-error "cannot be overloaded" }
-};
+}; // { dg-warning "invalid use of 'auto' in conversion operator" "" { target *-*-* } .-1 }
Funject fun;
auto bbb = fun(true);
// PR c++/84906
// { dg-do compile { target c++14 } }
+// { dg-options "-Wpedantic" }
extern "C" int puts(const char*);
struct aa {
- operator auto() {
+ operator auto() { // { dg-warning "invalid use of 'auto' in conversion operator" }
puts("auto");
return false;
}
// PR c++/65985
// { dg-do compile { target c++14 } }
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
+// { dg-options "" }
#include <cassert>
-// { dg-additional-options -fmodule-header }
+// { dg-options -fmodule-header }
// { dg-module-cmi {} }
#include "auto-1.h"
-// { dg-additional-options "-fmodules-ts -fno-module-lazy -fdump-lang-module-alias" }
+// { dg-options "-fmodules-ts -fno-module-lazy -fdump-lang-module-alias" }
#include "auto-1.h"
import "auto-1_a.H";
}
constexpr
- operator decltype(auto)() const noexcept
+ operator decltype(value)() const noexcept
{ return value; }
};