Index: clang/lib/AST/Interp/ByteCodeExprGen.h =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.h +++ clang/lib/AST/Interp/ByteCodeExprGen.h @@ -90,6 +90,8 @@ bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E); bool VisitOpaqueValueExpr(const OpaqueValueExpr *E); bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E); + bool VisitStringLiteral(const StringLiteral *E); + bool VisitCharacterLiteral(const CharacterLiteral *E); protected: bool visitExpr(const Expr *E) override; Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -432,6 +432,23 @@ return true; } +template +bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) { + unsigned StringIndex = P.createGlobalString(E); + return this->emitGetPtrGlobal(StringIndex, E); +} + +template +bool ByteCodeExprGen::VisitCharacterLiteral( + const CharacterLiteral *E) { + QualType LitType = E->getType(); + if (Optional T = classify(LitType)) { + APInt Val(getIntWidth(LitType), E->getValue()); + return this->emitConst(*T, 0, Val, E); + } + return this->bail(E); +} + template bool ByteCodeExprGen::discard(const Expr *E) { OptionScope Scope(this, /*NewDiscardResult=*/true); return this->Visit(E); Index: clang/test/AST/Interp/arrays.cpp =================================================================== --- clang/test/AST/Interp/arrays.cpp +++ clang/test/AST/Interp/arrays.cpp @@ -118,6 +118,22 @@ // expected-note {{cannot refer to element -2 of array of 10}} }; +namespace strings { + constexpr const char *S = "abc"; + static_assert(S[0] == 'a', ""); + static_assert(S[1] == 'b', ""); + static_assert(S[2] == 'c', ""); + static_assert(S[3] == '\0', ""); + + static_assert("foobar"[2] == 'o', ""); + + constexpr const wchar_t *wide = L"bar"; + static_assert(wide[0] == L'b', ""); + + constexpr const char32_t *u32 = U"abc"; + static_assert(u32[1] == U'b', ""); +}; + namespace fillers { constexpr int k[3] = {1337}; constexpr int foo(int m) {