From 3c5bd21a3e1201087ad30569fc1cee503073b37b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 20 Jul 2019 09:32:27 +0000 Subject: [PATCH] [c++20] P1161R3: a[b,c] is deprecated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366630 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 2 ++ include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaExpr.cpp | 9 ++++++++ test/SemaCXX/deprecated.cpp | 26 ++++++++++++++++++++++ www/cxx_status.html | 2 +- 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 56f2ecfe8e..daa430beaf 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/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/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b093b83760..fd185fdf4a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/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; def ext_subscript_non_lvalue : Extension< "ISO C90 does not allow subscripting non-lvalue array">; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d8869ffe94..401bb3c000 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/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(idx) && cast(idx)->isCommaOp()) || + (isa(idx) && + cast(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/test/SemaCXX/deprecated.cpp b/test/SemaCXX/deprecated.cpp index 773085bf2b..b5760c37cf 100644 --- a/test/SemaCXX/deprecated.cpp +++ b/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/www/cxx_status.html b/www/cxx_status.html index abb182c369..e9953bdb64 100755 --- a/www/cxx_status.html +++ b/www/cxx_status.html @@ -1098,7 +1098,7 @@ as the draft C++2a standard evolves. Deprecate a[b,c] P1161R3 - No + SVN Deprecate some problematic uses of volatile -- 2.50.0