[OB PATCH] Fix build errors in with clang in gdb.compile/compile-cplus.c
Pedro Alves
palves@redhat.com
Fri May 29 21:12:18 GMT 2020
On 5/29/20 5:43 PM, Gary Benson via Gdb-patches wrote:
> Clang fails to compile the file, with the following error:
> fatal error: 'iostream' file not found
>
> This prevents the following testcase from executing:
> gdb.compile/compile-cplus.exp
>
> The testcase sets additional_flags when building with GCC, which
> this commit causes to also be set when building with clang. This
> makes the testcase fail to build with a different error:
> warning: treating 'c' input as 'c++' when in C++ mode, this behavior
> is deprecated [-Wdeprecated]
> so this commit adds -Wno-deprecated in two places to sidestep this.
> Note that, while allowing the testcase to build, this commit reveals
> failures when the testsuite is built using clang.
>
> gdb/testsuite/ChangeLog:
>
> * gdb.compile/compile-cplus.exp (additional_flags): Also
> set when building with clang.
> (additional_flags, srcfilesoptions): Pass -Wno-deprecated
> when building with clang.
> ---
> gdb/testsuite/ChangeLog | 7 +++++++
> gdb/testsuite/gdb.compile/compile-cplus.exp | 15 +++++++++++++--
> 2 files changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.compile/compile-cplus.exp b/gdb/testsuite/gdb.compile/compile-cplus.exp
> index cca5b20..85b2f20 100644
> --- a/gdb/testsuite/gdb.compile/compile-cplus.exp
> +++ b/gdb/testsuite/gdb.compile/compile-cplus.exp
> @@ -19,11 +19,16 @@ standard_testfile .c compile-shlib.c compile-constvar.S compile-nodebug.c
>
> get_compiler_info
> set options {}
> -if [test_compiler_info gcc*] {
> +if { [test_compiler_info gcc*] || [test_compiler_info clang*] } {
> lappend options additional_flags=-g3
> lappend options additional_flags=-std=gnu++11
> lappend options c++
> }
> +if [test_compiler_info clang*] {
> + # Treating C input as C++ is deprecated in Clang, so
> + # the build will fail without disabling -Wdeprecated.
> + lappend options additional_flags=-Wno-deprecated
> +}
I think
lappend options "additional_flags=-x c++"
in the previous "if" would be better. Even better would be to tweak
gdb_compile or thereabouts to make the "c++" option automatically add
"-x c++" to the compiler options with clang. That would handle
everywhere this could be an issue all at once. WDYT?
BTW, it looks like a bug that appending the "c++" option is inside
the if, rather than outside.
Thanks,
Pedro Alves
>
> if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
> verbose "Skipping x86_64 LOC_CONST test."
> @@ -34,7 +39,13 @@ set srcfilesoptions [list ${srcfile} ${options}]
> if { $srcfile3 != "" } {
> lappend srcfilesoptions $srcfile3 ${options}
> }
> -lappend srcfilesoptions $srcfile4 "nodebug c++"
> +set srcfile4options "nodebug c++"
> +if [test_compiler_info clang*] {
> + # Treating C input as C++ is deprecated in Clang, so
> + # the build will fail without disabling -Wdeprecated.
> + set srcfile4options "$srcfile4options additional_flags=-Wno-deprecated"
> +}
> +lappend srcfilesoptions $srcfile4 $srcfile4options
> if { [eval build_executable_from_specs ${testfile}.exp $testfile {$options} ${srcfilesoptions}] } {
> return -1
> }
>
More information about the Gdb-patches
mailing list