aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2022-04-29 09:38:40 -0400
committerMarek Polacek <polacek@redhat.com>2022-04-29 09:38:55 -0400
commit19c62569ccf20d2744b63482a470474391d28c02 (patch)
treef5653f7bb6dfe8365b6cc94c3efd3ee22b12677a
parente1115a4f1b4afb346341237355186949f8e568a8 (diff)
downloadgcc-19c62569ccf20d2744b63482a470474391d28c02.zip
gcc-19c62569ccf20d2744b63482a470474391d28c02.tar.gz
gcc-19c62569ccf20d2744b63482a470474391d28c02.tar.bz2
c++: Add fixed test [PR78244]
This was finally fixed for GCC 11 by r11-434. PR c++/78244 gcc/testsuite/ChangeLog: * g++.dg/cpp0x/Wnarrowing20.C: New test.
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/Wnarrowing20.C26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing20.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing20.C
new file mode 100644
index 0000000..17a6001
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing20.C
@@ -0,0 +1,26 @@
+// PR c++/78244
+// { dg-do compile { target c++11 } }
+
+struct S { S(int); int d; };
+
+template <typename T>
+auto f1() -> decltype(S{2.0}, void()) { } // { dg-error "narrowing conversion" }
+
+template <typename T>
+auto f2() -> decltype(S{2.0}, 1) { return 1; } // { dg-error "narrowing conversion" }
+
+template <typename T>
+auto f3() -> decltype(void(), S{2.0}, 1) { return 1; } // { dg-error "narrowing conversion" }
+
+template <typename T>
+auto f4() -> decltype((S{2.0}, 1)) { return 1; } // { dg-error "narrowing conversion" }
+
+// Test OVERLOAD in a template.
+int id(int v) { return v; }
+double id(double v) { return v; }
+
+template <typename T>
+auto f5(double v) -> decltype((S{id(v)}, 1)) { return 1; } // { dg-error "narrowing conversion" }
+
+template <typename T>
+auto f6(int v) -> decltype((S{id(v)}, 1)) { return 1; }