aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-02-17 20:32:58 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-02-17 20:32:58 +0000
commit51679c5e4828b8a64953c4f3db162ca963bf7b03 (patch)
treeff09ba25f3ca73ca21509d2493aea3ee5c855bd0 /lib/Driver
parent679d6054072b04adac3eeb9508546e2485ad059f (diff)
PR5803: clang++: Treat untyped 'C' inputs as C++.
- Patch by Andrzej K. Haczewski, with a tweak by me to emit a 'deprecated' diagnostic when we do this. We'll see what zee users say. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96511 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver')
-rw-r--r--lib/Driver/Driver.cpp11
-rw-r--r--lib/Driver/Types.cpp16
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 15df767d97..e729f0fb54 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -558,6 +558,17 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
if (Ty == types::TY_INVALID)
Ty = types::TY_Object;
+
+ // If the driver is invoked as C++ compiler (like clang++ or c++) it
+ // should autodetect some input files as C++ for g++ compatibility.
+ if (CCCIsCXX) {
+ types::ID OldTy = Ty;
+ Ty = types::lookupCXXTypeForCType(Ty);
+
+ if (Ty != OldTy)
+ Diag(clang::diag::warn_drv_treating_input_as_cxx)
+ << getTypeName(OldTy) << getTypeName(Ty);
+ }
}
// -ObjC and -ObjC++ override the default language, but only for "source
diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp
index 60d86a62a3..8857fb16a3 100644
--- a/lib/Driver/Types.cpp
+++ b/lib/Driver/Types.cpp
@@ -213,3 +213,19 @@ phases::ID types::getCompilationPhase(ID Id, unsigned N) {
return phases::Link;
}
+
+ID types::lookupCXXTypeForCType(ID Id) {
+ switch (Id) {
+ default:
+ return Id;
+
+ case types::TY_C:
+ return types::TY_CXX;
+ case types::TY_PP_C:
+ return types::TY_PP_CXX;
+ case types::TY_CHeader:
+ return types::TY_CXXHeader;
+ case types::TY_PP_CHeader:
+ return types::TY_PP_CXXHeader;
+ }
+}