diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2023-12-16 10:59:03 +1100 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2023-12-16 15:09:50 +1100 |
commit | 39f9c426f58448d6df340cdccd84e05721a20921 (patch) | |
tree | ef54f6899319cba903a142e3fb98febc27600782 /gcc/cp/constexpr.cc | |
parent | 0cfde688e2133844a5d9b6cce9f2e73b620ba072 (diff) | |
download | gcc-39f9c426f58448d6df340cdccd84e05721a20921.zip gcc-39f9c426f58448d6df340cdccd84e05721a20921.tar.gz gcc-39f9c426f58448d6df340cdccd84e05721a20921.tar.bz2 |
c++: Fix unchecked use of CLASSTYPE_AS_BASE [PR113031]
My previous commit (naively) assumed that a TREE_CODE of RECORD_TYPE or
UNION_TYPE was sufficient for optype to be considered a "class type".
However, this does not account for e.g. template type parameters of
record or union type. This patch corrects to check for CLASS_TYPE_P
before checking for as-base conversion.
PR c++/113031
gcc/cp/ChangeLog:
* constexpr.cc (cxx_fold_indirect_ref_1): Check for CLASS_TYPE
before using CLASSTYPE_AS_BASE.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/pr113031.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r-- | gcc/cp/constexpr.cc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index e1b2d27..051f73f 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5709,7 +5709,8 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, } /* Handle conversion to "as base" type. */ - if (CLASSTYPE_AS_BASE (optype) == type) + if (CLASS_TYPE_P (optype) + && CLASSTYPE_AS_BASE (optype) == type) return op; /* Handle conversion to an empty base class, which is represented with a |