In finish_compound_literal, we perform non-dependent expr folding before
the call to check_narrowing ever since r9-5973. But ever since r10-7096,
check_narrowing also performs non-dependent expr folding of its own.
This double folding means tsubst will see non-templated trees during the
second folding, which causes a spurious error in the below testcase.
This patch removes the former folding operation; it seems obviated by
the latter one.
PR c++/104565
gcc/cp/ChangeLog:
* semantics.c (finish_compound_literal): Don't perform
non-dependent expr folding before calling check_narrowing.
gcc/testsuite/ChangeLog:
* g++.dg/template/non-dependent22.C: New test.
(cherry picked from commit
6bbd8afee0036c274f5ebb5b48d6fdc2091bd046)
return error_mark_node;
compound_literal = reshape_init (type, compound_literal, complain);
if (SCALAR_TYPE_P (type)
- && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal))
- {
- tree t = instantiate_non_dependent_expr_sfinae (compound_literal,
- complain);
- if (!check_narrowing (type, t, complain))
- return error_mark_node;
- }
+ && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
+ && !check_narrowing (type, compound_literal, complain))
+ return error_mark_node;
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE)
{
--- /dev/null
+// PR c++/104565
+// { dg-do compile { target c++11 } }
+
+struct apa {
+ constexpr int n() const { return 3; }
+};
+
+template<class>
+int f() {
+ apa foo;
+ return int{foo.n()}; // no matching function for call to 'apa::n(apa*)'
+}