Skip to content

Commit 4f69c4b

Browse files
committed
[clang][Interp] Don't diagnose reading const ints in C++98
We _can_ read them, even in C++98.
1 parent 12c2a53 commit 4f69c4b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
254254
if (VD->isConstexpr())
255255
return true;
256256

257+
QualType T = VD->getType();
257258
if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11)
258-
return false;
259+
return T->isSignedIntegerOrEnumerationType() || T->isUnsignedIntegerOrEnumerationType();
259260

260-
QualType T = VD->getType();
261261
if (T.isConstQualified())
262262
return true;
263263

clang/test/AST/Interp/cxx98.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ template struct C<cval>;
1818

1919
/// FIXME: This example does not get properly diagnosed in the new interpreter.
2020
extern const int recurse1;
21-
const int recurse2 = recurse1; // both-note {{declared here}}
21+
const int recurse2 = recurse1; // ref-note {{declared here}}
2222
const int recurse1 = 1;
2323
int array1[recurse1];
2424
int array2[recurse2]; // ref-warning 2{{variable length array}} \
2525
// ref-note {{initializer of 'recurse2' is not a constant expression}} \
2626
// expected-warning {{variable length array}} \
27-
// expected-note {{read of non-const variable 'recurse2'}} \
2827
// expected-error {{variable length array}}
2928

3029
int NCI; // both-note {{declared here}}
@@ -39,3 +38,10 @@ struct V {
3938
// both-error {{constructor cannot have a return type}}
4039
};
4140
_Static_assert(V().c[0], ""); // both-error {{is not an integral constant expression}}
41+
42+
struct C0 {
43+
template<typename U> static U Data; // both-warning {{C++14 extension}}
44+
template<typename U> static const U Data<U*> = U();
45+
};
46+
const int c0_test = C0::Data<int*>;
47+
_Static_assert(c0_test == 0, "");

0 commit comments

Comments
 (0)