]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888]
authorPatrick Palka <ppalka@redhat.com>
Tue, 30 Apr 2024 01:14:18 +0000 (21:14 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 30 Apr 2024 01:14:18 +0000 (21:14 -0400)
In the sizeof / sizeof operator expression handling we're missing
a dependence check for the second operand.

PR c++/114888

gcc/cp/ChangeLog:

* typeck.cc (cp_build_binary_op) <case *_DIV_*>: Add missing
dependence check for the second sizeof operand.

gcc/testsuite/ChangeLog:

* g++.dg/template/sizeof19.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/template/sizeof19.C [new file with mode: 0644]

index e5a52dc2b39a8d4822433edd7ef9c9bc202e12ba..a25f8622651dc8984dc336225ec72f376c95c5fe 100644 (file)
@@ -5501,6 +5501,7 @@ cp_build_binary_op (const op_location_t &location,
          if (!TYPE_P (type1))
            type1 = TREE_TYPE (type1);
          if (type0
+             && type1
              && INDIRECT_TYPE_P (type0)
              && same_type_p (TREE_TYPE (type0), type1))
            {
diff --git a/gcc/testsuite/g++.dg/template/sizeof19.C b/gcc/testsuite/g++.dg/template/sizeof19.C
new file mode 100644 (file)
index 0000000..a146799
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/114888
+
+template<class>
+struct A {
+  struct B {} *b;
+  static const int c = sizeof (b) / sizeof (b[0]);
+};
+const int d = A<int>::c;