[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
autoconf, clang static analyser and C++17
From: |
Peter Hull |
Subject: |
autoconf, clang static analyser and C++17 |
Date: |
Fri, 17 Feb 2023 14:30:57 +0000 |
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.
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
- autoconf, clang static analyser and C++17,
Peter Hull <=