diff options
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticGroups.td | 2 | ||||
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 9 | ||||
| -rw-r--r-- | clang/test/SemaCXX/deprecated.cpp | 26 | ||||
| -rwxr-xr-x | clang/www/cxx_status.html | 2 |
5 files changed, 41 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 56f2ecfe8e4..daa430beaf3 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -118,6 +118,7 @@ def CXX11CompatDeprecatedWritableStr : DiagGroup<"c++11-compat-deprecated-writable-strings">; def DeprecatedAttributes : DiagGroup<"deprecated-attributes">; +def DeprecatedCommaSubscript : DiagGroup<"deprecated-comma-subscript">; def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">; def UnavailableDeclarations : DiagGroup<"unavailable-declarations">; def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">; @@ -135,6 +136,7 @@ def DeprecatedWritableStr : DiagGroup<"deprecated-writable-strings", [CXX11CompatDeprecatedWritableStr]>; // FIXME: Why is DeprecatedImplementations not in this group? def Deprecated : DiagGroup<"deprecated", [DeprecatedAttributes, + DeprecatedCommaSubscript, DeprecatedDeclarations, DeprecatedDynamicExceptionSpec, DeprecatedIncrementBool, diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b093b83760b..fd185fdf4ab 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5719,6 +5719,9 @@ def err_arithmetic_nonfragile_interface : Error< "arithmetic on pointer to interface %0, which is not a constant size for " "this architecture and platform">; +def warn_deprecated_comma_subscript : Warning< + "top-level comma expression in array subscript is deprecated">, + InGroup<DeprecatedCommaSubscript>; def ext_subscript_non_lvalue : Extension< "ISO C90 does not allow subscripting non-lvalue array">; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d8869ffe945..401bb3c000b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4317,6 +4317,15 @@ Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base, SourceLocation lbLoc, base = result.get(); } + // A comma-expression as the index is deprecated in C++2a onwards. + if (getLangOpts().CPlusPlus2a && + ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) || + (isa<CXXOperatorCallExpr>(idx) && + cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma))) { + Diag(idx->getExprLoc(), diag::warn_deprecated_comma_subscript) + << SourceRange(base->getBeginLoc(), rbLoc); + } + // Handle any non-overload placeholder types in the base and index // expressions. We can't handle overloads here because the other // operand might be an overloadable type, in which case the overload diff --git a/clang/test/SemaCXX/deprecated.cpp b/clang/test/SemaCXX/deprecated.cpp index 773085bf2b9..b5760c37cf9 100644 --- a/clang/test/SemaCXX/deprecated.cpp +++ b/clang/test/SemaCXX/deprecated.cpp @@ -2,6 +2,7 @@ // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -triple x86_64-linux-gnu // RUN: %clang_cc1 -std=c++14 %s -Wdeprecated -verify -triple x86_64-linux-gnu // RUN: %clang_cc1 -std=c++17 %s -Wdeprecated -verify -triple x86_64-linux-gnu +// RUN: %clang_cc1 -std=c++2a %s -Wdeprecated -verify -triple x86_64-linux-gnu // RUN: %clang_cc1 -std=c++14 %s -Wdeprecated -verify -triple x86_64-linux-gnu -Wno-deprecated-register -DNO_DEPRECATED_FLAGS @@ -99,5 +100,30 @@ namespace DeprecatedCopy { } #endif +struct X { + friend int operator,(X, X); + void operator[](int); +}; +void array_index_comma() { + int arr[123]; + (void)arr[(void)1, 2]; + (void)arr[X(), X()]; + X()[(void)1, 2]; + X()[X(), X()]; +#if __cplusplus > 201703L + // expected-warning@-5 {{deprecated}} + // expected-warning@-5 {{deprecated}} + // expected-warning@-5 {{deprecated}} + // expected-warning@-5 {{deprecated}} +#endif + + (void)arr[((void)1, 2)]; + (void)arr[(X(), X())]; + (void)((void)1,2)[arr]; + (void)(X(), X())[arr]; + X()[((void)1, 2)]; + X()[(X(), X())]; +} + # 1 "/usr/include/system-header.h" 1 3 void system_header_function(void) throw(); diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html index abb182c3691..e9953bdb64d 100755 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -1098,7 +1098,7 @@ as the draft C++2a standard evolves. <tr> <td>Deprecate <tt>a[b,c]</tt></td> <td><a href="http://wg21.link/p1161r3">P1161R3</a></td> - <td class="none" align="center">No</td> + <td class="svn" align="center">SVN</td> </tr> <tr> <td>Deprecate some problematic uses of <tt>volatile</tt></td> |

