Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk/16?

-- >8 --

Here the nonsensical constraint-expression f() == 42 isn't getting
rejected ahead of time ultimately because we pass no_toplevel_fold_p=true
to cp_parser_binary_expression which makes it use build_min instead of
build_x_binary_op to avoid undesirable folding/canonicalization for sake
of OpenMP for loop parsing (r145014).  But this certainly doesn't happen
during templated parsing, and constraint-expressions are always
templated, so we might as well pass no_toplevel_fold_p=false here.

        PR c++/125490

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_constraint_expression): Pass
        no_toplevel_fold_p=false instead of =true to
        cp_parser_binary_expression.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp2a/concepts-pr125490.C: New test.
---
 gcc/cp/parser.cc                               |  2 +-
 gcc/testsuite/g++.dg/cpp2a/concepts-pr125490.C | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr125490.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b5c8c62118cc..c1797191b833 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -34761,7 +34761,7 @@ cp_parser_constraint_expression (cp_parser *parser)
 {
   processing_constraint_expression_sentinel parsing_constraint;
   ++processing_template_decl;
-  cp_expr expr = cp_parser_binary_expression (parser, false, true,
+  cp_expr expr = cp_parser_binary_expression (parser, false, false,
                                              PREC_NOT_OPERATOR, NULL);
   --processing_template_decl;
   if (check_for_bare_parameter_packs (expr))
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr125490.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-pr125490.C
new file mode 100644
index 000000000000..a33416b232d1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr125490.C
@@ -0,0 +1,10 @@
+// PR c++/125490
+// { dg-do compile { target c++20 } }
+
+void f();
+
+template<class T>
+concept C = f() == 42; // { dg-error "invalid operands" }
+
+template<class T>
+concept D = requires { requires f() == 42; }; // { dg-error "invalid operands" 
}
-- 
2.54.0.rc1.54.g60f07c4f5c

Reply via email to