scan-build:
- Only set the environment variable 'CXX' if the user specifies --use-c++.
- Fix regression when setting LDPLUSPLUS: add a 'which' to determine the location of g++.  This regression was pointed out by Jordan Breeding!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55780 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/scan-build b/utils/scan-build
index 705ad2c..540a60b 100755
--- a/utils/scan-build
+++ b/utils/scan-build
@@ -24,7 +24,7 @@
 my $Prog = "scan-build";
 my $BuildName;
 my $BuildDate;
-my $CXX = 'g++';
+my $CXX;  # Leave undefined initially.
 
 my $UseColor = ((($ENV{'TERM'} eq 'xterm-color') and -t STDOUT)
                 and defined($ENV{'SCAN_BUILD_COLOR'}));
@@ -692,7 +692,8 @@
     # When 'CC' is set, xcodebuild uses it to do all linking, even if we are
     # linking C++ object files.  Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
     # when linking such files.
-    my $LDPLUSPLUS = `$CXX`;
+    die if (!defined $CXX);
+    my $LDPLUSPLUS = `which $CXX`;
     $LDPLUSPLUS =~ s/\015?\012//;  # strip newlines
     $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS;    
   }
@@ -917,7 +918,14 @@
   Diag("Using 'clang' from path.\n");
 }
 
-$ENV{'CXX'} = $CXX;
+if (defined $CXX) {
+  $ENV{'CXX'} = $CXX;
+}
+else {
+  $CXX = 'g++';  # This variable is used by other parts of scan-build
+                 # that need to know a default C++ compiler to fall back to.
+}
+  
 $ENV{'CC'} = $Cmd;
 $ENV{'CLANG'} = $Clang;