On using C++17 for compilerplugins (not possible for now)
Stephan Bergmann
sbergman at redhat.com
Wed Nov 13 14:15:20 UTC 2019
I had accidentally developed patch set 1 of
<https://gerrit.libreoffice.org/#/c/82554/1> "Extend loplugin:salbool to
loplugin:fakebool" in an environment where compilerplugins was built
with -std=c++2a (and thus accidentally used some constructs that are not
compatible with the Clang 5.0.2 baseline of C++11).
I thought it would be nice to be able to use at least C++17 in
compilerplugins code, so I patched
> diff --git a/configure.ac b/configure.ac
> index 1711ea8a3623..fe4294b207cd 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -7040,6 +7040,26 @@ if test "$COM_IS_CLANG" = "TRUE"; then
> COMPILER_PLUGINS_CXXFLAGS="$COMPILER_PLUGINS_CXXFLAGS -I$clangobjdir/tools/clang/include"
> fi
> fi
> + dnl Use at least C++17 when building compilerplugins. There are three cases to consider:
> + dnl 1 If COMPILER_PLUGINS_CXX already contains a -std= option (i.e., passed in by the
> + dnl user), use it unconditionally (drop any potential -std= from
> + dnl COMPILER_PLUGINS_CXXFLAGS).
> + dnl 2 Otherwise, if COMPILER_PLUGINS_CXXFLAGS contains a -std= option (as is normally the
> + dnl case for `llvm-config --cxxflags`): If it is -std=c++11 or -std=c++14, replace it
> + dnl with -std=c++17. (And otherwise keep it.)
> + dnl 3 Otherwise (see e.g. <https://github.com/llvm/llvm-project/commit/
> + dnl 7a25de6d2073f77ea1a0d8f4cd715bec55678941> "llvm-config: emit the C++ standard flag
> + dnl into CXXFLAGS" for cases where it had gone missing from `llvm-config --cxxflags'),
> + dnl add -std=c++17 to COMPILER_PLUGINS_CXXFLAGS.
> + if printf '%s' "$COMPILER_PLUGINS_CXX" | grep -e -std=; then
> + COMPILER_PLUGINS_CXXFLAGS=$(printf '%s' "$COMPILER_PLUGINS_CXXFLAGS" \
> + | sed -e 's/-std=[[^ ]]*//')
> + elif printf '%s' "$COMPILER_PLUGINS_CXXFLAGS" | grep -e '-std=c++1[[14]]'; then
> + COMPILER_PLUGINS_CXXFLAGS=$(printf '%s' "$COMPILER_PLUGINS_CXXFLAGS" \
> + | sed -e 's/-std=[[^ ]]*/-std=c++17/')
> + elif ! printf '%s' "$COMPILER_PLUGINS_CXXFLAGS" | grep -e -std=; then
> + COMPILER_PLUGINS_CXXFLAGS="$COMPILER_PLUGINS_CXXFLAGS -std=c++17"
> + fi
> AC_MSG_NOTICE([compiler plugins compile flags: $COMPILER_PLUGINS_CXXFLAGS])
> AC_LANG_PUSH([C++])
> save_CXX=$CXX
in the hope that the Clang 5.0.2 baseline, and all the
COMPILER_PLUGINS_CXX used by people out there to build compilerplugins,
would be fine with -std=c++17.
However, both my local installs of Clang 5.0.2 and 6.0.0 would fail with
> [GEN] compilerplugins/clang/sharedvisitor/dllprivate.plugininfo
> analyzer: /data/sbergman/clang/5.0.2/src/tools/clang/lib/Serialization/ASTReader.cpp:7150: virtual clang::Stmt* clang::ASTReader::GetExternalDeclStmt(uint64_t): Assertion `NumCurrentElementsDeserializing == 0 && "should not be called while already deserializing"' failed.
> /bin/sh: line 1: 569762 Aborted (core dumped) /data/sbergman/lo-clang/core/compilerplugins/clang/sharedvisitor/analyzer /data/sbergman/lo-clang/core/compilerplugins/clang/dllprivate.cxx > /data/sbergman/lo-clang/core/compilerplugins/clang/sharedvisitor/dllprivate.plugininfo
> make[1]: *** [/data/sbergman/lo-clang/core/compilerplugins/Makefile-clang.mk:243: /data/sbergman/lo-clang/core/compilerplugins/clang/sharedvisitor/dllprivate.plugininfo] Error 134
> make[1]: Leaving directory '/data/sbergman/lo-clang/core'
etc., and only Clang 7.0.0 appears to have that fixed.
More information about the LibreOffice
mailing list