Author: rsmith Date: Sat Jul 20 02:32:27 2019 New Revision: 366630 URL: http://llvm.org/viewvc/llvm-project?rev=366630&view=rev Log: [c++20] P1161R3: a[b,c] is deprecated.
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/deprecated.cpp cfe/trunk/www/cxx_status.html Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=366630&r1=366629&r2=366630&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Sat Jul 20 02:32:27 2019 @@ -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<"d [CXX11CompatDeprecatedWritableStr]>; // FIXME: Why is DeprecatedImplementations not in this group? def Deprecated : DiagGroup<"deprecated", [DeprecatedAttributes, + DeprecatedCommaSubscript, DeprecatedDeclarations, DeprecatedDynamicExceptionSpec, DeprecatedIncrementBool, Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=366630&r1=366629&r2=366630&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Jul 20 02:32:27 2019 @@ -5719,6 +5719,9 @@ def err_arithmetic_nonfragile_interface "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">; Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=366630&r1=366629&r2=366630&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Jul 20 02:32:27 2019 @@ -4317,6 +4317,15 @@ Sema::ActOnArraySubscriptExpr(Scope *S, 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 Modified: cfe/trunk/test/SemaCXX/deprecated.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/deprecated.cpp?rev=366630&r1=366629&r2=366630&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/deprecated.cpp (original) +++ cfe/trunk/test/SemaCXX/deprecated.cpp Sat Jul 20 02:32:27 2019 @@ -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(); Modified: cfe/trunk/www/cxx_status.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=366630&r1=366629&r2=366630&view=diff ============================================================================== --- cfe/trunk/www/cxx_status.html (original) +++ cfe/trunk/www/cxx_status.html Sat Jul 20 02:32:27 2019 @@ -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> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits