diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-05-07 21:53:27 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-05-07 21:53:27 +0000 |
commit | 359a15d245c470904bc39940f45933330bb314b5 (patch) | |
tree | b7c05c1238db29c17931ade12e26b56728881ac1 /lib/Sema/SemaExpr.cpp | |
parent | f3e4763c6e533a1e34ea1440b11f85385bd0e2ec (diff) | |
download | clang-359a15d245c470904bc39940f45933330bb314b5.tar.gz clang-359a15d245c470904bc39940f45933330bb314b5.tar.bz2 clang-359a15d245c470904bc39940f45933330bb314b5.tar.xz |
Add an Extension warning for applying unary * to an operand of type 'void*' in
C++. This seems like a pointless (and indeed harmful) restriction to me, so
I've suggested removing it to -core and disabled this diagnostic by default.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208254 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e4b42402dc..979c28cbd8 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9026,10 +9026,6 @@ static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK, Op->getSourceRange()); } - // Note that per both C89 and C99, indirection is always legal, even if OpTy - // is an incomplete type or void. It would be possible to warn about - // dereferencing a void pointer, but it's completely well-defined, and such a - // warning is unlikely to catch any mistakes. if (const PointerType *PT = OpTy->getAs<PointerType>()) Result = PT->getPointeeType(); else if (const ObjCObjectPointerType *OPT = @@ -9048,6 +9044,19 @@ static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK, return QualType(); } + // Note that per both C89 and C99, indirection is always legal, even if Result + // is an incomplete type or void. It would be possible to warn about + // dereferencing a void pointer, but it's completely well-defined, and such a + // warning is unlikely to catch any mistakes. In C++, indirection is not valid + // for pointers to 'void' but is fine for any other pointer type: + // + // C++ [expr.unary.op]p1: + // [...] the expression to which [the unary * operator] is applied shall + // be a pointer to an object type, or a pointer to a function type + if (S.getLangOpts().CPlusPlus && Result->isVoidType()) + S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer) + << OpTy << Op->getSourceRange(); + // Dereferences are usually l-values... VK = VK_LValue; |