diff options
author | Tim Northover <tnorthover@apple.com> | 2017-08-08 23:18:05 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2017-08-08 23:18:05 +0000 |
commit | 0241637c0ea3e700942490951bbb2236cc6c2f3b (patch) | |
tree | 1e8dcc5dd5b7422f327c810b4f4bf0b1ae0ff513 /clang/lib/Sema/SemaChecking.cpp | |
parent | d1fafc8b0569b1cef000e1063657e2752f41ecb4 (diff) | |
download | bcm5719-llvm-0241637c0ea3e700942490951bbb2236cc6c2f3b.tar.gz bcm5719-llvm-0241637c0ea3e700942490951bbb2236cc6c2f3b.zip |
Sema: disable implicit conversion from _Complex to real types in C++.
Converting a _Complex type to a real one simply discards the imaginary part.
This can easily lead to loss of information so for safety (and GCC
compatibility) this patch disallows that when the conversion would be implicit.
The one exception is bool, which actually compares both real and imaginary
parts and so is safe.
llvm-svn: 310427
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 578dbf0aadc..bbb4b7592ed 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -9431,10 +9431,13 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T, // Strip complex types. if (isa<ComplexType>(Source)) { if (!isa<ComplexType>(Target)) { - if (S.SourceMgr.isInSystemMacro(CC)) + if (S.SourceMgr.isInSystemMacro(CC) || Target->isBooleanType()) return; - return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_complex_scalar); + return DiagnoseImpCast(S, E, T, CC, + S.getLangOpts().CPlusPlus + ? diag::err_impcast_complex_scalar + : diag::warn_impcast_complex_scalar); } Source = cast<ComplexType>(Source)->getElementType().getTypePtr(); |