tbaeder updated this revision to Diff 519479. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148689/new/
https://reviews.llvm.org/D148689 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/ByteCodeExprGen.h clang/test/AST/Interp/literals.cpp Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -831,3 +831,22 @@ } #endif + +namespace PredefinedExprs { +#if __cplusplus >= 201402L + constexpr bool strings_match(const char *str1, const char *str2) { + while (*str1 && *str2) { + if (*str1++ != *str2++) + return false; + }; + + return *str1 == *str2; + } + + void foo() { + static_assert(strings_match(__FUNCTION__, "foo")); + static_assert(strings_match(__func__, "foo")); + static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()")); + } +#endif +} Index: clang/lib/AST/Interp/ByteCodeExprGen.h =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.h +++ clang/lib/AST/Interp/ByteCodeExprGen.h @@ -96,6 +96,7 @@ bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); bool VisitTypeTraitExpr(const TypeTraitExpr *E); bool VisitLambdaExpr(const LambdaExpr *E); + bool VisitPredefinedExpr(const PredefinedExpr *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 @@ -1004,6 +1004,14 @@ return true; } +template <class Emitter> +bool ByteCodeExprGen<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) { + if (DiscardResult) + return true; + + return this->visit(E->getFunctionName()); +} + template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) { if (E->containsErrors()) return false;
Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -831,3 +831,22 @@ } #endif + +namespace PredefinedExprs { +#if __cplusplus >= 201402L + constexpr bool strings_match(const char *str1, const char *str2) { + while (*str1 && *str2) { + if (*str1++ != *str2++) + return false; + }; + + return *str1 == *str2; + } + + void foo() { + static_assert(strings_match(__FUNCTION__, "foo")); + static_assert(strings_match(__func__, "foo")); + static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()")); + } +#endif +} Index: clang/lib/AST/Interp/ByteCodeExprGen.h =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.h +++ clang/lib/AST/Interp/ByteCodeExprGen.h @@ -96,6 +96,7 @@ bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); bool VisitTypeTraitExpr(const TypeTraitExpr *E); bool VisitLambdaExpr(const LambdaExpr *E); + bool VisitPredefinedExpr(const PredefinedExpr *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 @@ -1004,6 +1004,14 @@ return true; } +template <class Emitter> +bool ByteCodeExprGen<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) { + if (DiscardResult) + return true; + + return this->visit(E->getFunctionName()); +} + template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) { if (E->containsErrors()) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits