[clang] [clang] Use the materialized temporary's type while creating the APValue (PR #73355)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 24 10:07:08 PST 2023
https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/73355
See https://github.com/llvm/llvm-project/issues/72025 for the bug and its diagnosis.
>From 3ff1b189cf55d3705b2823dc39eaaf710fa26541 Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Sat, 25 Nov 2023 02:01:22 +0800
Subject: [PATCH] [clang] Use the materialized temporary's type while creating
the APValue
See https://github.com/llvm/llvm-project/issues/72025 for the bug and
its diagnosis.
---
clang/docs/ReleaseNotes.rst | 3 +++
clang/lib/AST/ExprConstant.cpp | 2 +-
clang/test/SemaCXX/pr72025.cpp | 9 +++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 clang/test/SemaCXX/pr72025.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 74358219ba9fb22..d434d016907f815 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -691,6 +691,9 @@ Bug Fixes to C++ Support
Fixes:
(`#68769 <https://github.com/llvm/llvm-project/issues/68769>`_)
+- Fixed a crash for C++98/03 while checking an ill-formed ``_Static_assert`` expression.
+ Fixes: (`#72025 <https://github.com/llvm/llvm-project/issues/72025>`_)
+
- Clang now defers the instantiation of explicit specifier until constraint checking
completes (except deduction guides). Fixes:
(`#59827 <https://github.com/llvm/llvm-project/issues/59827>`_)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e16fec6109e744e..6c6ad12119d13c3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8607,7 +8607,7 @@ bool LValueExprEvaluator::VisitMaterializeTemporaryExpr(
Result.set(E);
} else {
Value = &Info.CurrentCall->createTemporary(
- E, E->getType(),
+ E, Inner->getType(),
E->getStorageDuration() == SD_FullExpression ? ScopeKind::FullExpression
: ScopeKind::Block,
Result);
diff --git a/clang/test/SemaCXX/pr72025.cpp b/clang/test/SemaCXX/pr72025.cpp
new file mode 100644
index 000000000000000..9f0a4b0f43630c5
--- /dev/null
+++ b/clang/test/SemaCXX/pr72025.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++03 -fsyntax-only %s
+struct V {
+ char c[2];
+ banana V() : c("i") {} // expected-error {{unknown type name}}
+ // expected-error at -1 {{constructor cannot have a return type}}
+};
+
+_Static_assert(V().c[0], ""); // expected-error {{is not an integral constant expression}}
+
More information about the cfe-commits
mailing list