Make sure we get extension diagnostics for GCC's complex extensions.
Now we emit the following when -pedantic-errors is enabled... [dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang complex.c -pedantic-errors complex.c:4:3: error: ISO C does not support '++'/'--' on complex integer types ++x; ^ ~ complex.c:9:7: error: ISO C does not support '~' for complex conjugation X = ~Y; ^ complex.c:10:7: error: ISO C does not support '~' for complex conjugation x = ~y; ^ llvm-svn: 41362
This commit is contained in:
parent
100198f3f7
commit
9d13917cff
|
@ -1256,18 +1256,23 @@ QualType Sema::CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc) {
|
||||||
QualType resType = op->getType();
|
QualType resType = op->getType();
|
||||||
assert(!resType.isNull() && "no type for increment/decrement expression");
|
assert(!resType.isNull() && "no type for increment/decrement expression");
|
||||||
|
|
||||||
// C99 6.5.2.4p1: C99 does not support ++/-- on complex types.
|
// C99 6.5.2.4p1: We allow complex as a GCC extension.
|
||||||
// We allow complex as a GCC extension.
|
|
||||||
if (const PointerType *pt = dyn_cast<PointerType>(resType)) {
|
if (const PointerType *pt = dyn_cast<PointerType>(resType)) {
|
||||||
if (!pt->getPointeeType()->isObjectType()) { // C99 6.5.2.4p2, 6.5.6p2
|
if (!pt->getPointeeType()->isObjectType()) { // C99 6.5.2.4p2, 6.5.6p2
|
||||||
Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type,
|
Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type,
|
||||||
resType.getAsString(), op->getSourceRange());
|
resType.getAsString(), op->getSourceRange());
|
||||||
return QualType();
|
return QualType();
|
||||||
}
|
}
|
||||||
} else if (!resType->isRealType() && !resType->isComplexType()) {
|
} else if (!resType->isRealType()) {
|
||||||
Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement,
|
if (resType->isComplexType())
|
||||||
resType.getAsString(), op->getSourceRange());
|
// C99 does not support ++/-- on complex types.
|
||||||
return QualType();
|
Diag(OpLoc, diag::ext_integer_increment_complex,
|
||||||
|
resType.getAsString(), op->getSourceRange());
|
||||||
|
else {
|
||||||
|
Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement,
|
||||||
|
resType.getAsString(), op->getSourceRange());
|
||||||
|
return QualType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// At this point, we know we have a real, complex or pointer type.
|
// At this point, we know we have a real, complex or pointer type.
|
||||||
// Now make sure the operand is a modifiable lvalue.
|
// Now make sure the operand is a modifiable lvalue.
|
||||||
|
@ -1555,11 +1560,16 @@ Action::ExprResult Sema::ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
|
||||||
case UnaryOperator::Not: // bitwise complement
|
case UnaryOperator::Not: // bitwise complement
|
||||||
UsualUnaryConversions(Input);
|
UsualUnaryConversions(Input);
|
||||||
resultType = Input->getType();
|
resultType = Input->getType();
|
||||||
// C99 6.5.3.3p1. C99 does not support '~' for complex conjugation.
|
// C99 6.5.3.3p1. We allow complex as a GCC extension.
|
||||||
// We allow complex as a GCC extension.
|
if (!resultType->isIntegerType()) {
|
||||||
if (!resultType->isIntegerType() && !resultType->isComplexType())
|
if (resultType->isComplexType())
|
||||||
return Diag(OpLoc, diag::err_typecheck_unary_expr,
|
// C99 does not support '~' for complex conjugation.
|
||||||
resultType.getAsString());
|
Diag(OpLoc, diag::ext_integer_complement_complex,
|
||||||
|
resultType.getAsString());
|
||||||
|
else
|
||||||
|
return Diag(OpLoc, diag::err_typecheck_unary_expr,
|
||||||
|
resultType.getAsString());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case UnaryOperator::LNot: // logical negation
|
case UnaryOperator::LNot: // logical negation
|
||||||
// Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5).
|
// Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5).
|
||||||
|
|
|
@ -275,6 +275,10 @@ DIAG(ext_integer_complex, EXTENSION,
|
||||||
"ISO C does not support complex integer types")
|
"ISO C does not support complex integer types")
|
||||||
DIAG(ext_thread_before, EXTENSION,
|
DIAG(ext_thread_before, EXTENSION,
|
||||||
"'__thread' before 'static'")
|
"'__thread' before 'static'")
|
||||||
|
DIAG(ext_integer_increment_complex, EXTENSION,
|
||||||
|
"ISO C does not support '++'/'--' on complex integer types")
|
||||||
|
DIAG(ext_integer_complement_complex, EXTENSION,
|
||||||
|
"ISO C does not support '~' for complex conjugation")
|
||||||
|
|
||||||
DIAG(ext_empty_struct_union_enum, EXTENSION,
|
DIAG(ext_empty_struct_union_enum, EXTENSION,
|
||||||
"use of empty %0 extension")
|
"use of empty %0 extension")
|
||||||
|
|
Loading…
Reference in New Issue