[PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 18 13:47:15 PDT 2016
erichkeane created this revision.
erichkeane added reviewers: cfe-commits, majnemer, vbyakovl, DavidKreitzer, andreybokhanko, rsmith.
erichkeane set the repository for this revision to rL LLVM.
GCC (and other compilers) treat strlen as a 'constexpr' function as an extension to the language. Clang previously treated __builtin_strlen as a constexpr extension, so for this patch it was only necessary to remove the error-causing diagnostic for the strlen case, which falls through to the __builtin_strlen handling.
Additionally, the strlen test previously expected this error, so this patch removes the error-expectation from the test.
Repository:
rL LLVM
https://reviews.llvm.org/D23692
Files:
lib/AST/ExprConstant.cpp
test/SemaCXX/constexpr-strlen.cpp
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7022,11 +7022,9 @@
}
case Builtin::BIstrlen:
- // A call to strlen is not a constant expression.
- if (Info.getLangOpts().CPlusPlus11)
- Info.CCEDiag(E, diag::note_constexpr_invalid_function)
- << /*isConstexpr*/0 << /*isConstructor*/0 << "'strlen'";
- else
+ // As a GCC compatibility extension, we support strlen()
+ // as a constant expression.
+ if (!Info.getLangOpts().CPlusPlus11)
Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
// Fall through.
case Builtin::BI__builtin_strlen: {
Index: test/SemaCXX/constexpr-strlen.cpp
===================================================================
--- test/SemaCXX/constexpr-strlen.cpp
+++ test/SemaCXX/constexpr-strlen.cpp
@@ -8,7 +8,7 @@
# 10 "SemaCXX/constexpr-strlen.cpp" 2
constexpr int n = __builtin_strlen("hello"); // ok
-constexpr int m = strlen("hello"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strlen' cannot be used in a constant expression}}
+constexpr int m = strlen("hello"); // ok
// Make sure we can evaluate a call to strlen.
int arr[3]; // expected-note {{here}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23692.68599.patch
Type: text/x-patch
Size: 1308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160818/a39980dd/attachment.bin>
More information about the cfe-commits
mailing list