[gcc r11-9751] c-family: ICE with -Wconversion and A ?: B [PR101030]
Marek Polacek
mpolacek@gcc.gnu.org
Wed Mar 30 14:27:45 GMT 2022
https://gcc.gnu.org/g:511e8b612287ad828c60f2f12c500ccfa26c275c
commit r11-9751-g511e8b612287ad828c60f2f12c500ccfa26c275c
Author: Marek Polacek <polacek@redhat.com>
Date: Tue Mar 29 14:36:55 2022 -0400
c-family: ICE with -Wconversion and A ?: B [PR101030]
This patch fixes a crash in conversion_warning on a null expression.
It is null because the testcase uses the GNU A ?: B extension. We
could also use op0 instead of op1 in this case, but it doesn't seem
to be necessary.
PR c++/101030
gcc/c-family/ChangeLog:
* c-warn.c (conversion_warning) <case COND_EXPR>: Don't call
conversion_warning when OP1 is null.
gcc/testsuite/ChangeLog:
* g++.dg/ext/cond5.C: New test.
(cherry picked from commit 5db9ce171019f8915885cebd5cc5f4101bb926e6)
Diff:
---
gcc/c-family/c-warn.c | 2 +-
gcc/testsuite/g++.dg/ext/cond5.C | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index abd6adcfe9a..96bee7d1984 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -1300,7 +1300,7 @@ conversion_warning (location_t loc, tree type, tree expr, tree result)
tree op1 = TREE_OPERAND (expr, 1);
tree op2 = TREE_OPERAND (expr, 2);
- return (conversion_warning (loc, type, op1, result)
+ return ((op1 && conversion_warning (loc, type, op1, result))
|| conversion_warning (loc, type, op2, result));
}
diff --git a/gcc/testsuite/g++.dg/ext/cond5.C b/gcc/testsuite/g++.dg/ext/cond5.C
new file mode 100644
index 00000000000..a92f28998f9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/cond5.C
@@ -0,0 +1,13 @@
+// PR c++/101030
+// { dg-do compile { target { c++11 } } }
+// { dg-options "-Wconversion" }
+
+template <int N>
+struct jj {
+ int ii[N ?: 1];
+ char c = N ?: 1; // { dg-warning "conversion from .int. to .char. changes value from .300. to " }
+};
+
+int main() {
+ jj<300> kk;
+}
More information about the Gcc-cvs
mailing list