autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: autoconf, clang static analyser and C++17


From: Arsen Arsenović
Subject: Re: autoconf, clang static analyser and C++17
Date: Fri, 17 Feb 2023 17:20:11 +0100

Hi Peter,

Peter Hull <peterhull90@gmail.com> writes:

> Hi,
> I've got a problem running scan-build on some C++ 17 code and I'm not
> sure if the cause is me, scan-build or autoconf. I'd welcome any
> advice.
>
> I've made a small test case:(still long, sorry)
>
> $ cat configure.ac
> #                                               -*- Autoconf -*-
> # Process this file with autoconf to produce a configure script.
>
> AC_PREREQ([2.71])
> AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
> AC_CONFIG_SRCDIR([me.cc])
> AC_CONFIG_MACRO_DIR([m4])
>
> AC_PROG_CXX
> AX_CXX_COMPILE_STDCXX([17])
>
> AC_CONFIG_FILES([Makefile])
> AC_OUTPUT
>
> $ cat Makefile.in
> CXXFLAGS:=@CXXFLAGS@
> CXX:=@CXX@
>
> all: me
>
> clean:
>         -rm me
>
> $ cat me.cc
> #include <string>
> #include <string_view>
> #include <iostream>
>
> int main() {
>   std::string_view s("Hello");
>   std::cout << std::string(s) << std::endl;
>   return 0;
> }
>
>
> I've put the AX_CXX_COMPILE_STDCXX macro from
> https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
> into ./m4/
>
> I ran aclocal and autoconf then ./configure && make, and everything is fine.
>
> However scan-build ./configure && scan-build --keep-cc make gives me
> errors because it can't find std::string_view
>
> /usr/bin/../libexec/c++-analyzer -g -O2    me.cc   -o me
> me.cc:6:19: error: expected ';' after expression
>   std::string_view s("Hello");
>                   ^
>                   ;
> me.cc:6:8: error: no member named 'string_view' in namespace 'std'
>   std::string_view s("Hello");
>   ~~~~~^
>
> which I am assuming is because string_view was new in C++17 and the
> analyzer is defaulting to some version prior to that. In fact I can
> specify '-std=c++17' explicitly in the CXXFLAGS given to configure and
> it works.
>
> However, the purpose of the AX_CXX_COMPILE_STDCXX is to handle that
> for me I believe. During normal configuration I see this:
>
> $ ./configure
> checking for g++... g++
> ...lines omitted...
> checking for g++ option to enable C++11 features... none needed
> checking whether g++ supports C++17 features by default... yes
> configure: creating ./config.status
> config.status: creating Makefile
>
>
> $ scan-build ./configure
> scan-build: Using '/usr/bin/clang-15' for static analysis
> ...lines omitted...
> checking for /usr/bin/../libexec/c++-analyzer option to enable C++11
> features... none needed
> checking whether /usr/bin/../libexec/c++-analyzer supports C++17
> features by default... yes
> configure: creating ./config.status
> config.status: creating Makefile
>
> So I think maybe AX_CXX_COMPILE_STDCXX believes that a -std= flag
> isn't needed but it is.

AFAIU, scan-build inserts a fake compiler that compiles code using the
real compiler also.  This might be why you don't see failures while
configuring but do after configuring.  I believe that Clang 15 still
places the compilation standard at -std=gnu++14.  Most likely, it just
happens that the tests inside AX_CXX_COMPILE_STDCXX fail to catch this
discrepancy.  If I were you, I'd likely just pass CXXFLAGS=-std=c++17 to
the scan-build configure invocation and see if that works.

AX_CXX_COMPILE_STDCXX will not insert any flags if it believes that the
compiler already defaults to the desired or superior version of the
standard.  I am not sure why this behavior was chosen.

> Does this make sense? What do you think?
>
> Final bit:
> I'm running Fedora 37, autoconf (GNU Autoconf) 2.71,
> AX_CXX_COMPILE_STDCXX v15 (2021),  g++ (GCC) 12.2.1, and clang version
> 15.0.7
>
> Thanks,
> Peter

Hope that helps, have a lovely day.
-- 
Arsen Arsenović

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]