]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Respect current_constraint_diagnosis_depth in diagnose_compound_requirement
authorPatrick Palka <ppalka@redhat.com>
Sat, 28 Mar 2020 12:56:33 +0000 (08:56 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 28 Mar 2020 12:56:33 +0000 (08:56 -0400)
The previous patch tries to avoid changing our current default diagnostics.  But
for the sake of consistency we arguably should also respect
current_constraint_diagnosis_depth in diagnose_compound_requirement() like we do
in the other error-replaying diagnostic routines.  But doing so would be a
change to our default diagnostics behavior, so the change has been split out
into this separate patch for separate consideration.

gcc/cp/ChangeLog:

* constraint.cc (diagnose_compound_requirement): When diagnosing a
compound requirement, maybe replay the satisfaction failure, subject to
the current diagnosis depth.

gcc/testsuite/ChangeLog:

* g++.dg/concepts/diagnostic1.C: Pass -fconcepts-diagnostics-depth=2.
* g++.dg/concepts/diagnostic5.C: Adjust expected diagnostics.
* g++.dg/cpp2a/concepts-iconv1.C: Pass -fconcepts-diagnostics-depth=2.
* g++.dg/cpp2a/concepts-requires5.C: Likewise.

gcc/cp/ChangeLog
gcc/cp/constraint.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/concepts/diagnostic1.C
gcc/testsuite/g++.dg/concepts/diagnostic5.C
gcc/testsuite/g++.dg/cpp2a/concepts-iconv1.C
gcc/testsuite/g++.dg/cpp2a/concepts-requires5.C

index a65ed1414787b86c311d6da188dc92a5b0da9c38..be67685d0c2d20e691fc2fe79f364cbd5c7184a1 100644 (file)
@@ -1,5 +1,9 @@
 2020-03-28  Patrick Palka  <ppalka@redhat.com>
 
+       * constraint.cc (diagnose_compound_requirement): When diagnosing a
+       compound requirement, maybe replay the satisfaction failure, subject to
+       the current diagnosis depth.
+
        * constraint.cc (finish_constraint_binary_op): Set the location of EXPR
        as well as its range, because build_x_binary_op doesn't always do so.
        (current_constraint_diagnosis_depth): New.
index 76c520318c347ccd68a2d93a232314f64a61c5af..571c7cbdd38bf217a771044da0f3be5dfe279b5c 100644 (file)
@@ -3308,20 +3308,30 @@ diagnose_compound_requirement (tree req, tree args, tree in_decl)
          if (!type_deducible_p (expr, type, placeholder, args, quiet))
            {
              tree orig_expr = TREE_OPERAND (req, 0);
-             inform (loc, "%qE does not satisfy return-type-requirement",
-                     orig_expr);
-
-             /* Further explain the reason for the error.  */
-             type_deducible_p (expr, type, placeholder, args, noisy);
+             if (diagnosing_failed_constraint::replay_errors_p ())
+               {
+                 inform (loc,
+                         "%qE does not satisfy return-type-requirement, "
+                         "because", orig_expr);
+                 /* Further explain the reason for the error.  */
+                 type_deducible_p (expr, type, placeholder, args, noisy);
+               }
+             else
+               inform (loc, "%qE does not satisfy return-type-requirement",
+                       orig_expr);
            }
        }
       else if (!expression_convertible_p (expr, type, quiet))
        {
          tree orig_expr = TREE_OPERAND (req, 0);
-         inform (loc, "cannot convert %qE to %qT", orig_expr, type);
-
-         /* Further explain the reason for the error.  */
-         expression_convertible_p (expr, type, noisy);
+         if (diagnosing_failed_constraint::replay_errors_p ())
+           {
+             inform (loc, "cannot convert %qE to %qT because", orig_expr, type);
+             /* Further explain the reason for the error.  */
+             expression_convertible_p (expr, type, noisy);
+           }
+         else
+           inform (loc, "cannot convert %qE to %qT", orig_expr, type);
        }
     }
 }
index f60813f1d26c294404939a6e4152ba83f3eb6a3f..e2e00f4c2b43a93028dbc83976c7fab4d29799d1 100644 (file)
@@ -1,5 +1,10 @@
 2020-03-28  Patrick Palka  <ppalka@redhat.com>
 
+       * g++.dg/concepts/diagnostic1.C: Pass -fconcepts-diagnostics-depth=2.
+       * g++.dg/concepts/diagnostic5.C: Adjust expected diagnostics.
+       * g++.dg/cpp2a/concepts-iconv1.C: Pass -fconcepts-diagnostics-depth=2.
+       * g++.dg/cpp2a/concepts-requires5.C: Likewise.
+
        * g++.dg/concepts/diagnostic2.C: Expect "no operand" instead of
        "neither operand".
        * g++.dg/concepts/diagnostic5.C: New test.
index 7da08db27920f46b715ce70e67cc286f9d86b06e..c6589e2e67189e672ca4ad71f1cab4ec5f471227 100644 (file)
@@ -1,6 +1,7 @@
 // PR c++/67159
 // { dg-do compile { target c++17_only } }
 // { dg-options "-fconcepts" }
+// { dg-additional-options "-fconcepts-diagnostics-depth=2" }
 
 template <class T, class U>
 concept bool SameAs = __is_same_as(T, U);
index 2641dc1842397c4afff6fee0f5df215ef7f8f310..0d890d6f5489b432f5a89c3e6611a1d5b89fea64 100644 (file)
@@ -4,8 +4,7 @@
 template<typename T>
   concept c1 = requires { typename T::blah; };
 // { dg-message "satisfaction of .c1<T>. .with T = char." "" { target *-*-* } .-1 }
-// { dg-message "satisfaction of .c1<char\\*>." "" { target *-*-* } .-2 }
-// { dg-message ".typename T::blah. is invalid" "" { target *-*-* } .-3 }
+// { dg-message ".typename T::blah. is invalid" "" { target *-*-* } .-2 }
 
 template<typename T>
   concept c2 = requires (T x) { *x; };
@@ -27,8 +26,6 @@ template<typename T>
   concept c5 = requires (T x) { { &x } -> c1; };
 // { dg-message "satisfaction of .c5<T>. .with T = char." "" { target *-*-* } .-1 }
 // { dg-message "in requirements with .char x." "" { target *-*-* } .-2 }
-// { dg-message "does not satisfy return-type-requirement" "" { target *-*-* } .-3 }
-// { dg-error "deduced expression type does not satisfy" "" { target *-*-* } .-4 }
 
 template<typename T>
   requires (c1<T> || c2<T>) || (c3<T> || c4<T>) || c5<T> // { dg-message "49: no operand" }
index 4d521c30748f6b31cb2d58bfa156d34d08183ddc..4e2d13f8eb3a129ebeab5b0f6326225410d6c31f 100644 (file)
@@ -1,5 +1,6 @@
 // PR c++/67240
 // { dg-do compile { target c++2a } }
+// { dg-additional-options "-fconcepts-diagnostics-depth=2" }
 
 template <class T, class U> concept Same = __is_same_as(T,U);
 
index 133d29e45a439b5ca3c676d00caefd6d7e30b38f..2f912b13d6ad52c920b10cd547811524e3cca5aa 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do compile { target c++2a } }
-// { dg-additional-options -fconcepts-ts }
+// { dg-additional-options "-fconcepts-ts -fconcepts-diagnostics-depth=2" }
 
 // Test conversion requirements (not in C++20)