Properly handle typos in the conditional of ?: expressions in C.

In particular, remove the OpaqueExpr transformation from r225389 and
move the correction of the conditional from CheckConditionalOperands to
ActOnConditionalOp before the OpaqueExpr is created. This fixes the
typo correction behavior in C code that uses the GNU extension for a
binary ?: (without an expression between the "?" and the ":").

llvm-svn: 227220
This commit is contained in:
Kaelyn Takata 2015-01-27 18:26:18 +00:00
parent b1e6c2dd3d
commit 05f4050928
3 changed files with 14 additions and 15 deletions

View File

@ -5785,15 +5785,6 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
ExprObjectKind &OK,
SourceLocation QuestionLoc) {
if (!getLangOpts().CPlusPlus) {
// C cannot handle TypoExpr nodes on either side of a binop because it
// doesn't handle dependent types properly, so make sure any TypoExprs have
// been dealt with before checking the operands.
ExprResult CondResult = CorrectDelayedTyposInExpr(Cond);
if (!CondResult.isUsable()) return QualType();
Cond = CondResult;
}
ExprResult LHSResult = CheckPlaceholderExpr(LHS.get());
if (!LHSResult.isUsable()) return QualType();
LHS = LHSResult;
@ -6175,6 +6166,15 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
SourceLocation ColonLoc,
Expr *CondExpr, Expr *LHSExpr,
Expr *RHSExpr) {
if (!getLangOpts().CPlusPlus) {
// C cannot handle TypoExpr nodes in the condition because it
// doesn't handle dependent types properly, so make sure any TypoExprs have
// been dealt with before checking the operands.
ExprResult CondResult = CorrectDelayedTyposInExpr(CondExpr);
if (!CondResult.isUsable()) return ExprError();
CondExpr = CondResult.get();
}
// If this is the gnu "x ?: y" extension, analyze the types as though the LHS
// was the condition.
OpaqueValueExpr *opaqueValue = nullptr;

View File

@ -6146,12 +6146,6 @@ public:
ExprResult TransformLambdaExpr(LambdaExpr *E) { return Owned(E); }
ExprResult TransformOpaqueValueExpr(OpaqueValueExpr *E) {
if (Expr *SE = E->getSourceExpr())
return TransformExpr(SE);
return BaseTransform::TransformOpaqueValueExpr(E);
}
ExprResult Transform(Expr *E) {
ExprResult Res;
while (true) {

View File

@ -13,6 +13,11 @@ void PR21656() {
a = b ? : 0; // expected-warning {{type specifier missing, defaults to 'int'}} \
// expected-error {{use of undeclared identifier 'b'}}
int foobar; // expected-note {{'foobar' declared here}}
a = goobar ?: 4; // expected-warning {{type specifier missing, defaults to 'int'}} \
// expected-error {{use of undeclared identifier 'goobar'; did you mean 'foobar'?}} \
// expected-error {{initializer element is not a compile-time constant}}
struct ContainerStuct {
enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}}
};