public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-10149] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888]
@ 2024-04-30  1:21 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2024-04-30  1:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3c925ac349b03ae9439c632fb1c042cdc8d78f40

commit r14-10149-g3c925ac349b03ae9439c632fb1c042cdc8d78f40
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Apr 29 21:14:18 2024 -0400

    c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888]
    
    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>
    (cherry picked from commit 3900e944b0ac9db77380c5bb8635977dfd3b0691)

Diff:
---
 gcc/cp/typeck.cc                         | 1 +
 gcc/testsuite/g++.dg/template/sizeof19.C | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index e5a52dc2b39..a25f8622651 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -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
index 00000000000..a1467995a9b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/sizeof19.C
@@ -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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-30  1:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30  1:21 [gcc r14-10149] c++: ICE with templated sizeof(E1) / sizeof(E2) [PR114888] Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).