@@ -1835,6 +1835,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
1835
1835
// / primary-expression
1836
1836
// / postfix-expression '[' expression ']'
1837
1837
// / postfix-expression '[' braced-init-list ']'
1838
+ // / postfix-expression '[' expression-list [opt] ']' [C++2b 12.4.5]
1838
1839
// / postfix-expression '(' argument-expression-list[opt] ')'
1839
1840
// / postfix-expression '.' identifier
1840
1841
// / postfix-expression '->' identifier
@@ -1898,30 +1899,58 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1898
1899
(void )Actions.CorrectDelayedTyposInExpr (LHS);
1899
1900
return ExprError ();
1900
1901
}
1901
-
1902
1902
BalancedDelimiterTracker T (*this , tok::l_square);
1903
1903
T.consumeOpen ();
1904
1904
Loc = T.getOpenLocation ();
1905
- ExprResult Idx, Length, Stride;
1905
+ ExprResult Length, Stride;
1906
1906
SourceLocation ColonLocFirst, ColonLocSecond;
1907
+ ExprVector ArgExprs;
1908
+ bool HasError = false ;
1907
1909
PreferredType.enterSubscript (Actions, Tok.getLocation (), LHS.get ());
1908
- if (getLangOpts ().CPlusPlus11 && Tok.is (tok::l_brace)) {
1909
- Diag (Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1910
- Idx = ParseBraceInitializer ();
1911
- } else if (getLangOpts ().OpenMP ) {
1912
- ColonProtectionRAIIObject RAII (*this );
1913
- // Parse [: or [ expr or [ expr :
1914
- if (!Tok.is (tok::colon)) {
1915
- // [ expr
1916
- Idx = ParseExpression ();
1910
+
1911
+ // We try to parse a list of indexes in all language mode first
1912
+ // and, in we find 0 or one index, we try to parse an OpenMP array
1913
+ // section. This allow us to support C++2b multi dimensional subscript and
1914
+ // OpenMp sections in the same language mode.
1915
+ if (!getLangOpts ().OpenMP || Tok.isNot (tok::colon)) {
1916
+ if (!getLangOpts ().CPlusPlus2b ) {
1917
+ ExprResult Idx;
1918
+ if (getLangOpts ().CPlusPlus11 && Tok.is (tok::l_brace)) {
1919
+ Diag (Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1920
+ Idx = ParseBraceInitializer ();
1921
+ } else {
1922
+ Idx = ParseExpression (); // May be a comma expression
1923
+ }
1924
+ LHS = Actions.CorrectDelayedTyposInExpr (LHS);
1925
+ Idx = Actions.CorrectDelayedTyposInExpr (Idx);
1926
+ if (Idx.isInvalid ()) {
1927
+ HasError = true ;
1928
+ } else {
1929
+ ArgExprs.push_back (Idx.get ());
1930
+ }
1931
+ } else if (Tok.isNot (tok::r_square)) {
1932
+ CommaLocsTy CommaLocs;
1933
+ if (ParseExpressionList (ArgExprs, CommaLocs)) {
1934
+ LHS = Actions.CorrectDelayedTyposInExpr (LHS);
1935
+ HasError = true ;
1936
+ }
1937
+ assert (
1938
+ (ArgExprs.empty () || ArgExprs.size () == CommaLocs.size () + 1 ) &&
1939
+ " Unexpected number of commas!" );
1917
1940
}
1941
+ }
1942
+
1943
+ if (ArgExprs.size () <= 1 && getLangOpts ().OpenMP ) {
1944
+ ColonProtectionRAIIObject RAII (*this );
1918
1945
if (Tok.is (tok::colon)) {
1919
1946
// Consume ':'
1920
1947
ColonLocFirst = ConsumeToken ();
1921
1948
if (Tok.isNot (tok::r_square) &&
1922
1949
(getLangOpts ().OpenMP < 50 ||
1923
- ((Tok.isNot (tok::colon) && getLangOpts ().OpenMP >= 50 ))))
1950
+ ((Tok.isNot (tok::colon) && getLangOpts ().OpenMP >= 50 )))) {
1924
1951
Length = ParseExpression ();
1952
+ Length = Actions.CorrectDelayedTyposInExpr (Length);
1953
+ }
1925
1954
}
1926
1955
if (getLangOpts ().OpenMP >= 50 &&
1927
1956
(OMPClauseKind == llvm::omp::Clause::OMPC_to ||
@@ -1933,27 +1962,23 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1933
1962
Stride = ParseExpression ();
1934
1963
}
1935
1964
}
1936
- } else
1937
- Idx = ParseExpression ();
1965
+ }
1938
1966
1939
1967
SourceLocation RLoc = Tok.getLocation ();
1940
-
1941
1968
LHS = Actions.CorrectDelayedTyposInExpr (LHS);
1942
- Idx = Actions.CorrectDelayedTyposInExpr (Idx);
1943
- Length = Actions.CorrectDelayedTyposInExpr (Length);
1944
- if (!LHS.isInvalid () && !Idx.isInvalid () && !Length.isInvalid () &&
1969
+
1970
+ if (!LHS.isInvalid () && !HasError && !Length.isInvalid () &&
1945
1971
!Stride.isInvalid () && Tok.is (tok::r_square)) {
1946
1972
if (ColonLocFirst.isValid () || ColonLocSecond.isValid ()) {
1947
1973
LHS = Actions.ActOnOMPArraySectionExpr (
1948
- LHS.get (), Loc, Idx. get (), ColonLocFirst, ColonLocSecond ,
1949
- Length.get (), Stride.get (), RLoc);
1974
+ LHS.get (), Loc, ArgExprs. empty () ? nullptr : ArgExprs[ 0 ] ,
1975
+ ColonLocFirst, ColonLocSecond, Length.get (), Stride.get (), RLoc);
1950
1976
} else {
1951
1977
LHS = Actions.ActOnArraySubscriptExpr (getCurScope (), LHS.get (), Loc,
1952
- Idx. get () , RLoc);
1978
+ ArgExprs , RLoc);
1953
1979
}
1954
1980
} else {
1955
1981
LHS = ExprError ();
1956
- Idx = ExprError ();
1957
1982
}
1958
1983
1959
1984
// Match the ']'.
0 commit comments