Skip to content

Commit 9472c4c

Browse files
committed
[cxx-interop] Avoid "libstdc++ not found" warning when -nostdinc++ is passed
When explicitly asked not to load the C++ standard library, Swift should not emit warnings for missing libstdc++. This fixes a compiler warning when building the Cxx module on Linux.
1 parent ecf7ac9 commit 9472c4c

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ static void getLibStdCxxFileMapping(
288288
stdlibArgStrings);
289289
auto parsedStdlibArgs = parseClangDriverArgs(clangDriver, stdlibArgStrings);
290290

291+
// If we were explicitly asked to not bring in the C++ stdlib, bail.
292+
if (parsedStdlibArgs.hasArg(clang::driver::options::OPT_nostdinc,
293+
clang::driver::options::OPT_nostdincxx,
294+
clang::driver::options::OPT_nostdlibinc))
295+
return;
296+
291297
Path cxxStdlibDir;
292298
if (auto dir = findFirstIncludeDir(parsedStdlibArgs,
293299
{"cstdlib", "string", "vector"}, vfs)) {

test/Interop/Cxx/stdlib/Inputs/module.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ module StdFunction {
6969
requires cplusplus
7070
export *
7171
}
72+
73+
module NoCXXStdlib {
74+
header "no-cxx-stdlib.h"
75+
requires cplusplus
76+
export *
77+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file intentionally does not import anything from the C++ stdlib.
2+
3+
inline int my_sum(int a, int b) {
4+
return a + b;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -nostdinc++
2+
3+
import NoCXXStdlib
4+
5+
let _ = my_sum(12, 15)

0 commit comments

Comments
 (0)