c++: Don't allow type-constraint auto(x) [PR104752]
authorMarek Polacek <polacek@redhat.com>
Wed, 2 Mar 2022 17:12:33 +0000 (12:12 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 10 Mar 2022 16:22:40 +0000 (11:22 -0500)
commit97f76b5fc4b637033229e53033b4f8b6dc23472c
tree55f2a369772fc52fbba7886a31818f2639c7114b
parentac8310dd122172bf9d7217e3367da55f9bf9b21b
c++: Don't allow type-constraint auto(x) [PR104752]

104752 points out that

  template<class T>
  concept C = true;
  auto y = C auto(1);

is ill-formed as per [dcl.type.auto.deduct]: "For an explicit type conversion,
T is the specified type, which shall be auto." which doesn't allow
type-constraint auto.

PR c++/104752

gcc/cp/ChangeLog:

* semantics.cc (finish_compound_literal): Disallow auto{x} for
is_constrained_auto.
* typeck2.cc (build_functional_cast_1): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/auto-fncast12.C: New test.
gcc/cp/semantics.cc
gcc/cp/typeck2.cc
gcc/testsuite/g++.dg/cpp23/auto-fncast12.C [new file with mode: 0644]