Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
Here when trying to translate a standard library #include into import
<bits/stdc++.h> we gave a hard error if stdc++.h did not exist, which breaks
using an alternate standard library. Let's make the check fail silently by
using the __has_include mode.
It's awkward to add a test for this because dejagnu always adds the
libstdc++ headers so an -I in the testcase options is never searched; I had
to override ALWAYS_CXXFLAGS for this one testcase in module.exp.
PR c++/127940
libcpp/ChangeLog:
* files.cc (_cpp_stack_include): Use _cpp_FFK_HAS_INCLUDE
to check for an alternate header.
gcc/testsuite/ChangeLog:
* g++.dg/modules/inc-xlate-5.C: New test.
* g++.dg/modules/dummy-stdlib/stdexcept: For new test.
* g++.dg/modules/modules.exp: Override ALWAYS_CXXFLAGS for it.
---
gcc/testsuite/g++.dg/modules/inc-xlate-5.C | 4 ++++
libcpp/files.cc | 4 ++--
.../g++.dg/modules/dummy-stdlib/stdexcept | 1 +
gcc/testsuite/g++.dg/modules/modules.exp | 14 ++++++++++++++
4 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/modules/inc-xlate-5.C
create mode 100644 gcc/testsuite/g++.dg/modules/dummy-stdlib/stdexcept
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-5.C
b/gcc/testsuite/g++.dg/modules/inc-xlate-5.C
new file mode 100644
index 00000000000..fa4b13ec221
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-5.C
@@ -0,0 +1,4 @@
+// PR c++/127940
+// { dg-additional-options "-fmodules -nostdinc++ -I[srcdir]/dummy-stdlib" }
+
+#include <stdexcept> // { dg-bogus {bits/stdc} }
diff --git a/libcpp/files.cc b/libcpp/files.cc
index b0ecb00de24..ead247b338b 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -1190,8 +1190,8 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname,
int angle_brackets,
if (!buf && aname)
{
_cpp_file *afile = _cpp_find_file (pfile, aname, dir, angle_brackets,
- _cpp_FFK_NORMAL, loc);
- if (afile && !afile->header_unit)
+ _cpp_FFK_HAS_INCLUDE, loc);
+ if (afile && !afile->deferred_error && !afile->header_unit)
buf = (pfile->cb.translate_include
(pfile, pfile->line_table, loc,
afile, angle_brackets, nullptr));
diff --git a/gcc/testsuite/g++.dg/modules/dummy-stdlib/stdexcept
b/gcc/testsuite/g++.dg/modules/dummy-stdlib/stdexcept
new file mode 100644
index 00000000000..68007d8c234
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/dummy-stdlib/stdexcept
@@ -0,0 +1 @@
+// This file intentionally left blank.
diff --git a/gcc/testsuite/g++.dg/modules/modules.exp
b/gcc/testsuite/g++.dg/modules/modules.exp
index a34c76a8051..7fb3ee50437 100644
--- a/gcc/testsuite/g++.dg/modules/modules.exp
+++ b/gcc/testsuite/g++.dg/modules/modules.exp
@@ -359,6 +359,18 @@ foreach test [prune [lsort [find $srcdir/$subdir
{*.[CH]}]] \
if [runtest_file_p $runtests $test] {
set nshort [file tail [file dirname $test]]/[file tail $test]
+ # Kludge: inc-xlate-5.C doesn't want the libstdc++ headers, and
+ # g++_init put them in ALWAYS_CXXFLAGS, so we need to temporarily
+ # remove them for that test. libstdc++-v3/scripts/testsuite_flags
+ # --build-includes always starts with -nostdinc++, so that's how we
+ # recognize the block we want to remove.
+ global ALWAYS_CXXFLAGS
+ set always $ALWAYS_CXXFLAGS
+ if [string match "*inc-xlate-5*" $test] {
+ set ALWAYS_CXXFLAGS [regsub {\{additional_flags=-nostdinc[^\}]+\}}
$ALWAYS_CXXFLAGS ""]
+ verbose "set ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS" 1
+ }
+
set std_list [module-init $test]
foreach std $std_list {
global module_cmis
@@ -372,6 +384,8 @@ foreach test [prune [lsort [find $srcdir/$subdir {*.[CH]}]]
\
set testcase [string range $test [string length "$srcdir/"] end]
cleanup_module_files [module_cmi_p $testcase $module_cmis $std]
}
+
+ set ALWAYS_CXXFLAGS $always
}
}
base-commit: bcf14085d8270f173ee6f1f4f9ae8352959e5ca1
--
2.56.0