diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a51f5add7dfdbbb86b5202be8f56fc3b71e79892..0191354e84b9ce115647776ead0bf44a2b40a8cd 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5956,7 +5956,9 @@ void Parser::ParseDirectDeclarator(Declarator &D) { DeclaratorScopeObj DeclScopeObj(*this, D.getCXXScopeSpec()); // Add language judgement for BSC template entrance. - if ((getLangOpts().CPlusPlus || getLangOpts().BSC) && D.mayHaveIdentifier()) { + if ((getLangOpts().CPlusPlus || + (getLangOpts().BSC && Actions.getCurScope()->isTemplateParamScope())) && + D.mayHaveIdentifier()) { // This might be a C++17 structured binding. if (Tok.is(tok::l_square) && !D.mayOmitIdentifier() && D.getCXXScopeSpec().isEmpty()) @@ -6230,9 +6232,11 @@ void Parser::ParseDirectDeclarator(Declarator &D) { // is not, the declarator has been fully parsed. bool IsAmbiguous = false; - // Add language judgement for BSC template entrance. - // Change branch entering condition | BSC syntax reusing C++ parsing code - if ((getLangOpts().CPlusPlus || getLangOpts().BSC) && + // Add language judgement for BSC template entrance. Change branch + // entering condition | BSC syntax reusing C++ parsing code + if ((getLangOpts().CPlusPlus || + (getLangOpts().BSC) && + Actions.getCurScope()->getParent()->isTemplateParamScope()) && D.mayBeFollowedByCXXDirectInit()) { // The name of the declarator, if any, is tentatively declared within // a possible direct initializer. diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 1ef83f6e6f9f059ae4de0e6c57eed2cf61c07427..25dade7c268766e80b67fde109ae9985f8b7abbf 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -3110,15 +3110,19 @@ bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, SourceLocation IdLoc = ConsumeToken(); if (!getLangOpts().CPlusPlus) { - // at BSC syntax T max(T a, T b) {...} - // ^ - if (getLangOpts().BSC && Tok.is(tok::less)) { + // We add this judge to parse BSC syntax, without + // affecting the original logic of C. + // @Code:k + // T max(T a, T b) {...} + // @EndCode + if (Actions.getCurScope()->isTemplateParamScope() && + (getLangOpts().BSC && Tok.is(tok::less))) { // TODO: we should refactoring check logic, abandon assert. assert(Tok.is(tok::less) && "expected 'less' token"); while (!Tok.is(tok::greater)) { ConsumeToken(); } - if(Tok.is(tok::greater)) { + if (Tok.is(tok::greater)) { ConsumeToken(); } else { Diag(Tok.getLocation(), diag::err_expected_comma_greater); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5bb97ef3d6c927141fa1d1ea9cf1654cd55816dc..b132228b41bb0b49032a6e459332fe9a459de6ad 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -14605,7 +14605,9 @@ ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc, // overloaded op. if (LHSExpr->isTypeDependent() || RHSExpr->isTypeDependent()) return BuildOverloadedBinOp(*this, S, OpLoc, Opc, LHSExpr, RHSExpr); + } + if (getLangOpts().CPlusPlus) { // Otherwise, build an overloaded op if either expression has an // overloadable type. if (LHSExpr->getType()->isOverloadableType() || diff --git a/clang/test/BSC/Generic/normal_c_logic_1.cbs b/clang/test/BSC/Generic/normal_c_logic_1.cbs new file mode 100644 index 0000000000000000000000000000000000000000..d16e29160479d13ef43bdea1bb36aedbacb42e2e --- /dev/null +++ b/clang/test/BSC/Generic/normal_c_logic_1.cbs @@ -0,0 +1,20 @@ +// RUN: %clang %s -o %t.output +// RUN: %t.output +// expected-no-diagnostics + +#include + +struct f { + int len; +}; + +int f(struct f* m) { + if (m->len + +int m(bool i) { + return 0; +} + +int main() { + return 0; +} + diff --git a/clang/test/BSC/Generic/normal_c_logic_4.cbs b/clang/test/BSC/Generic/normal_c_logic_4.cbs new file mode 100644 index 0000000000000000000000000000000000000000..20b1f495a62b4900707aef2e3ab6e61b49a096c2 --- /dev/null +++ b/clang/test/BSC/Generic/normal_c_logic_4.cbs @@ -0,0 +1,15 @@ +// RUN: %clang %s -o %t.output +// RUN: %t.output +// expected-no-diagnostics + +struct Runtime { + int a; +}; +struct Runtime runtime; + +int main() { + struct Runtime a; + runtime = a; + return 0; +} +