From 99046d23d78d341674bbad3414567f362ffc60cd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 13 Mar 2021 12:04:07 +0200 Subject: Tighten Clang detection not to misdetect GCC built with Clang GitHub issue #136. --- libbuild2/cc/guess.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libbuild2') diff --git a/libbuild2/cc/guess.cxx b/libbuild2/cc/guess.cxx index 1e0c77a..d80fd17 100644 --- a/libbuild2/cc/guess.cxx +++ b/libbuild2/cc/guess.cxx @@ -1016,6 +1016,8 @@ namespace build2 : guess_result ()); } + size_t p; + // The gcc -v output will have a last line in the form: // // "gcc version X.Y.Z ..." @@ -1111,7 +1113,12 @@ namespace build2 // The clang-cl output is exactly the same, which means the only way // to distinguish it is based on the executable name. // - if (l.find ("clang ") != string::npos) + // We must also watch out for potential misdetections, for example: + // + // Configured with: ../gcc/configure CC=clang CXX=clang++ ... + // + if ((p = l.find ("clang ")) != string::npos && + (p == 0 || l[p - 1] == ' ')) { if (cache.empty ()) { -- cgit v1.1