aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-03-15 15:50:42 +0100
committerTimm Bäder <tbaeder@redhat.com>2024-03-15 16:43:43 +0100
commit4f69c4b158969386deaf42028d4511ef7a015a20 (patch)
tree07bba395c9f9feb87d036377da1e776d5e4c4ff9 /clang
parent12c2a53e6ae5e1ee33de5811341a10bcdc7a8c4f (diff)
downloadllvm-4f69c4b158969386deaf42028d4511ef7a015a20.zip
llvm-4f69c4b158969386deaf42028d4511ef7a015a20.tar.gz
llvm-4f69c4b158969386deaf42028d4511ef7a015a20.tar.bz2
[clang][Interp] Don't diagnose reading const ints in C++98
We _can_ read them, even in C++98.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/Interp/Interp.cpp4
-rw-r--r--clang/test/AST/Interp/cxx98.cpp10
2 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 4f3cd6c..1b9f3cf 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -254,10 +254,10 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
if (VD->isConstexpr())
return true;
+ QualType T = VD->getType();
if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11)
- return false;
+ return T->isSignedIntegerOrEnumerationType() || T->isUnsignedIntegerOrEnumerationType();
- QualType T = VD->getType();
if (T.isConstQualified())
return true;
diff --git a/clang/test/AST/Interp/cxx98.cpp b/clang/test/AST/Interp/cxx98.cpp
index 73e4537..ba6bcd9 100644
--- a/clang/test/AST/Interp/cxx98.cpp
+++ b/clang/test/AST/Interp/cxx98.cpp
@@ -18,13 +18,12 @@ template struct C<cval>;
/// FIXME: This example does not get properly diagnosed in the new interpreter.
extern const int recurse1;
-const int recurse2 = recurse1; // both-note {{declared here}}
+const int recurse2 = recurse1; // ref-note {{declared here}}
const int recurse1 = 1;
int array1[recurse1];
int array2[recurse2]; // ref-warning 2{{variable length array}} \
// ref-note {{initializer of 'recurse2' is not a constant expression}} \
// expected-warning {{variable length array}} \
- // expected-note {{read of non-const variable 'recurse2'}} \
// expected-error {{variable length array}}
int NCI; // both-note {{declared here}}
@@ -39,3 +38,10 @@ struct V {
// both-error {{constructor cannot have a return type}}
};
_Static_assert(V().c[0], ""); // both-error {{is not an integral constant expression}}
+
+struct C0 {
+ template<typename U> static U Data; // both-warning {{C++14 extension}}
+ template<typename U> static const U Data<U*> = U();
+};
+const int c0_test = C0::Data<int*>;
+_Static_assert(c0_test == 0, "");