aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-12-13 16:46:04 -0500
committerPatrick Palka <ppalka@redhat.com>2023-12-13 16:46:04 -0500
commitd6840b3143f617065a070857cb22d826d24c622b (patch)
tree7895f53620efbc9ecc0fc8d87d7e31966f7580b2 /gcc/testsuite
parentb24c09bfb626271cda345f5a6f0d3a6b6480593d (diff)
downloadgcc-d6840b3143f617065a070857cb22d826d24c622b.zip
gcc-d6840b3143f617065a070857cb22d826d24c622b.tar.gz
gcc-d6840b3143f617065a070857cb22d826d24c622b.tar.bz2
c++: note other candidates when diagnosing deletedness
With the previous two patches in place, we can now extend our deletedness diagnostic to note the other considered candidates, e.g.: deleted.C: In function 'int main()': deleted.C:10:4: error: use of deleted function 'void f(int)' 10 | f(0); | ~^~~ deleted.C:5:6: note: declared here 5 | void f(int) = delete; | ^ deleted.C:5:6: note: candidate: 'void f(int)' (deleted) deleted.C:6:6: note: candidate: 'void f(...)' 6 | void f(...); | ^ deleted.C:7:6: note: candidate: 'void f(int, int)' 7 | void f(int, int); | ^ deleted.C:7:6: note: candidate expects 2 arguments, 1 provided These notes are controlled by a new command line flag -fdiagnostics-all-candidates which also controls whether we note ignored candidates more generally. gcc/ChangeLog: * doc/invoke.texi (C++ Dialect Options): Document -fdiagnostics-all-candidates. gcc/c-family/ChangeLog: * c.opt: Add -fdiagnostics-all-candidates. gcc/cp/ChangeLog: * call.cc (print_z_candidates): Only print ignored candidates when -fdiagnostics-all-candidates is set, otherwise suggest the flag. (build_over_call): When diagnosing deletedness, note other candidates only if -fdiagnostics-all-candidates is set, otherwise suggest the flag. gcc/testsuite/ChangeLog: * g++.dg/overload/error6.C: Pass -fdiagnostics-all-candidates. * g++.dg/cpp0x/deleted16.C: New test. * g++.dg/cpp0x/deleted16a.C: New test. * g++.dg/overload/error6a.C: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/deleted16.C25
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/deleted16a.C12
-rw-r--r--gcc/testsuite/g++.dg/overload/error6.C1
-rw-r--r--gcc/testsuite/g++.dg/overload/error6a.C6
4 files changed, 44 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted16.C b/gcc/testsuite/g++.dg/cpp0x/deleted16.C
new file mode 100644
index 0000000..d434794
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/deleted16.C
@@ -0,0 +1,25 @@
+// Verify -fdiagnostics-all-candidates makes us note other candidates
+// when a deleted function is selected by overload resolution.
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fdiagnostics-all-candidates" }
+
+void f(int) = delete; // { dg-message "declared here" }
+void f(...); // { dg-message "candidate" }
+void f(int, int); // { dg-message "candidate" }
+
+// An example where the perfect candidate optimization causes us
+// to ignore function templates.
+void g(int) = delete; // { dg-message "declared here" }
+template<class T> void g(T); // { dg-message "candidate" }
+
+// An example where we have a strictly viable candidate and
+// an incompletely considered bad candidate.
+template<class T> void h(T, T) = delete; // { dg-message "declared here|candidate" }
+void h(int*, int) = delete; // { dg-message "candidate" }
+
+int main() {
+ f(0); // { dg-error "deleted" }
+ g(0); // { dg-error "deleted" }
+ h(1, 1); // { dg-error "deleted" }
+ // { dg-error "invalid conversion" "" { target *-*-* } .-1 } when noting 2nd cand
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted16a.C b/gcc/testsuite/g++.dg/cpp0x/deleted16a.C
new file mode 100644
index 0000000..e62306f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/deleted16a.C
@@ -0,0 +1,12 @@
+// Verify we suggest -fdiagnostics-all-candidates when diagnosing
+// overload resolution selecting a deleted function.
+// { dg-do compile { target c++11 } }
+#include "deleted16.C"
+
+// { dg-error "deleted" "" { target *-*-* } 21 }
+// { dg-error "deleted" "" { target *-*-* } 22 }
+// { dg-error "deleted" "" { target *-*-* } 23 }
+
+// { dg-message "use '-fdiagnostics-all-candidates'" "" { target *-*-* } 21 }
+// { dg-message "use '-fdiagnostics-all-candidates'" "" { target *-*-* } 22 }
+// { dg-message "use '-fdiagnostics-all-candidates'" "" { target *-*-* } 23 }
diff --git a/gcc/testsuite/g++.dg/overload/error6.C b/gcc/testsuite/g++.dg/overload/error6.C
index 86a12ea..3186a29 100644
--- a/gcc/testsuite/g++.dg/overload/error6.C
+++ b/gcc/testsuite/g++.dg/overload/error6.C
@@ -1,5 +1,6 @@
// Verify we note even non-template candidates when diagnosing
// overload resolution failure for a template-id.
+// { dg-additional-options "-fdiagnostics-all-candidates" }
template<class T> void f(T); // { dg-message "candidate" }
void f(int); // { dg-message {candidate: 'void f\(int\)' \(ignored\)} }
diff --git a/gcc/testsuite/g++.dg/overload/error6a.C b/gcc/testsuite/g++.dg/overload/error6a.C
new file mode 100644
index 0000000..e86ab51
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/error6a.C
@@ -0,0 +1,6 @@
+// Verify we suggest -fdiagnostics-all-candidates when there are
+// omitted candidates.
+#include "error6.C"
+
+// { dg-error "no match" "" { target *-*-* } 9 }
+// { dg-message "use '-fdiagnostics-all-candidates'" "" { target *-*-* } 9 }