From 778796853dbb42b1ede1f347fac5312831bb22b1 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 9 Aug 2023 14:34:17 +0200 Subject: [PATCH] CONFIG: enable use of stricter deprecation warnings - selected with '+strict' in WM_COMPILE_CONTROL or 'wmake -strict', it enables the FOAM_DEPRECATED_STRICT() macro, which can be used to mark methods that are implicitly deprecated, but are not yet marked as full deprecated (eg, API modification is too recent, generates too many warnings). Can be considered a developer option. --- .../test/Dictionary/Test-Dictionary.C | 10 ++++---- .../test/UDictionary/Test-UDictionary.C | 7 ++---- .../test/compoundToken1/Test-compoundToken1.C | 10 ++++++++ etc/bashrc | 1 + etc/config.sh/completion_cache | 2 +- etc/cshrc | 1 + src/OpenFOAM/include/stdFoam.H | 7 ++++++ wmake/rules/General/general | 5 ++++ wmake/scripts/AllwmakeParseArguments | 18 ++++++++----- wmake/wmake | 25 +++++++++++++++++-- 10 files changed, 67 insertions(+), 19 deletions(-) diff --git a/applications/test/Dictionary/Test-Dictionary.C b/applications/test/Dictionary/Test-Dictionary.C index 41d772ecb8..7238260ba5 100644 --- a/applications/test/Dictionary/Test-Dictionary.C +++ b/applications/test/Dictionary/Test-Dictionary.C @@ -55,7 +55,7 @@ public: i_(i) {} - word& keyword() const noexcept { return keyword_; } + const word& keyword() const noexcept { return keyword_; } friend Ostream& operator<<(Ostream& os, const ent& e) { @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) dict.swapDown(dict.first()); - forAllConstIter(Dictionary, dict, iter) + forAllConstIters(dict, iter) { Info<< "element : " << *iter; } @@ -153,9 +153,9 @@ int main(int argc, char *argv[]) } Info<< nl << "scalarDict1: " << endl; - forAllConstIter(PtrDictionary, scalarDict, iter) + forAllConstIters(scalarDict, iter) { - Info<< " = " << iter() << endl; + Info<< " = " << *iter << endl; } PtrDictionary scalarDict2; @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) scalarDict2.insert(key, new Scalar(1.3*i)); } Info<< nl << "scalarDict2: " << endl; - forAllConstIter(PtrDictionary, scalarDict2, iter) + forAllConstIters(scalarDict2, iter) { std::cout<< "iter: " << typeid(*iter).name() << '\n'; diff --git a/applications/test/UDictionary/Test-UDictionary.C b/applications/test/UDictionary/Test-UDictionary.C index a0ed48b862..4418b4e18c 100644 --- a/applications/test/UDictionary/Test-UDictionary.C +++ b/applications/test/UDictionary/Test-UDictionary.C @@ -51,10 +51,7 @@ public: i_(i) {} - const word& keyword() const - { - return keyword_; - } + const word& keyword() const noexcept { return keyword_; } friend Ostream& operator<<(Ostream& os, const ent& e) { @@ -83,7 +80,7 @@ int main(int argc, char *argv[]) dict.swapDown(dict.first()); - forAllConstIter(UDictionary, dict, iter) + forAllConstIters(dict, iter) { Info<< "element : " << *iter; } diff --git a/applications/test/compoundToken1/Test-compoundToken1.C b/applications/test/compoundToken1/Test-compoundToken1.C index 4acbd5e747..8eabd24fb1 100644 --- a/applications/test/compoundToken1/Test-compoundToken1.C +++ b/applications/test/compoundToken1/Test-compoundToken1.C @@ -110,6 +110,13 @@ public: //- Destructor ~IFstreamDelayed() = default; + + // Testing deprecation warnings + FOAM_DEPRECATED_STRICT(2023-08, "direct calling") + Istream& operator()() const + { + return const_cast(*this); + } }; @@ -281,6 +288,9 @@ int main(int argc, char *argv[]) IFstreamDelayed is(args[argi]); + // Trigger strict warning? + Info<< "stream: " << is().name() << nl; + dictionary dict(is); Info<< "read: " << dict << nl; diff --git a/etc/bashrc b/etc/bashrc index e4cb5fb72d..9151a94faf 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -92,6 +92,7 @@ export WM_COMPILE_OPTION=Opt # ~openmp : without openmp # +ccache : use ccache # +xcrun : use xcrun and native compilers [MacOS] +# +strict : more deprecation warnings (may generate *many* warnings) # ccache=... : ccache command (unquoted, single/double or <> quoted) # version=... : compiler suffix (eg, "11" for gcc-11) #export WM_COMPILE_CONTROL="+gold" diff --git a/etc/config.sh/completion_cache b/etc/config.sh/completion_cache index c53d6a48a4..f05ed40810 100644 --- a/etc/config.sh/completion_cache +++ b/etc/config.sh/completion_cache @@ -284,6 +284,6 @@ _of_complete_cache_[XiEngineFoam]="-case -decomposeParDict -fileHandler -world | _of_complete_cache_[XiFoam]="-case -decomposeParDict -fileHandler -world | -dry-run -dry-run-write -listFunctionObjects -listFvOptions -listRegisteredSwitches -listScalarBCs -listSwitches -listTurbulenceModels -listUnsetSwitches -listVectorBCs -mpi-threads -noFunctionObjects -parallel -postProcess -doc -help" _of_complete_cache_[zipUpMesh]="-case -decomposeParDict -fileHandler -region -world | -mpi-threads -noFunctionObjects -parallel -doc -help" _of_complete_cache_[paraFoam]="-case -region | -block -vtk -touch -touch-all -touch-proc -plugin-path= -help" -_of_complete_cache_[wmake]=" | -s -a -q -k -j -update -debug -debug-O[g0123] -build-root= -module-prefix= -module-prefix= -no-openfoam -openmp -no-openmp -no-scheduler -show-api -show-ext-so -show-c -show-cflags -show-cxx -show-cxxflags -show-cflags-arch -show-cxxflags-arch -show-compile-c -show-compile-cxx -show-path-c -show-path-cxx -show-mpi-compile -show-mpi-link -show-openmp-compile -show-openmp-link -pwd -version -help" +_of_complete_cache_[wmake]=" | -s -a -q -k -j -update -debug -debug-O[g0123] -strict -build-root= -module-prefix= -module-prefix= -no-openfoam -openmp -no-openmp -no-scheduler -show-api -show-ext-so -show-c -show-cflags -show-cxx -show-cxxflags -show-cflags-arch -show-cxxflags-arch -show-compile-c -show-compile-cxx -show-path-c -show-path-cxx -show-mpi-compile -show-mpi-link -show-openmp-compile -show-openmp-link -pwd -version -help" #------------------------------------------------------------------------------ diff --git a/etc/cshrc b/etc/cshrc index 19f5849746..079505d3dd 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -92,6 +92,7 @@ setenv WM_COMPILE_OPTION Opt # ~openmp : without openmp # +ccache : use ccache # +xcrun : use xcrun and native compilers [MacOS] +# +strict : more deprecation warnings (may generate *many* warnings) # ccache=... : ccache command (unquoted, single/double or <> quoted) # version=... : compiler suffix (eg, "11" for gcc-11) #setenv WM_COMPILE_CONTROL "+gold" diff --git a/src/OpenFOAM/include/stdFoam.H b/src/OpenFOAM/include/stdFoam.H index 1f986544e6..55b25b34d5 100644 --- a/src/OpenFOAM/include/stdFoam.H +++ b/src/OpenFOAM/include/stdFoam.H @@ -46,12 +46,19 @@ Description #if (__cplusplus >= 201402L) # define FOAM_DEPRECATED(since) [[deprecated("Since " #since)]] # define FOAM_DEPRECATED_FOR(since, replacement) [[deprecated("Since " #since "; use " #replacement)]] +# define FOAM_DEPRECATED_STRICT(since, replacement) [[deprecated("Since " #since "; use " #replacement)]] #elif defined(__GNUC__) # define FOAM_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) # define FOAM_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) +# define FOAM_DEPRECATED_STRICT(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) #else # define FOAM_DEPRECATED(since) # define FOAM_DEPRECATED_FOR(since, replacement) +# define FOAM_DEPRECATED_STRICT(since, replacement) +#endif +#ifndef FOAM_COMPILE_STRICT +# undef FOAM_DEPRECATED_STRICT +# define FOAM_DEPRECATED_STRICT(since, replacement) #endif // Compile-time warning about unused result diff --git a/wmake/rules/General/general b/wmake/rules/General/general index 049b28b780..b3ae8e8218 100644 --- a/wmake/rules/General/general +++ b/wmake/rules/General/general @@ -32,6 +32,11 @@ else COMPILER_VERSION := endif +# Enable additional compile-time checks +ifneq (,$(findstring +strict,$(WM_COMPILE_CONTROL))) + GFLAGS += -DFOAM_COMPILE_STRICT +endif + # Default compilation is 'Opt' - never permit an empty value ifeq (,$(strip $(WM_COMPILE_OPTION))) WM_COMPILE_OPTION := Opt diff --git a/wmake/scripts/AllwmakeParseArguments b/wmake/scripts/AllwmakeParseArguments index 93fe183f02..0f5ddeea8e 100644 --- a/wmake/scripts/AllwmakeParseArguments +++ b/wmake/scripts/AllwmakeParseArguments @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2014-2017 OpenFOAM Foundation -# Copyright (C) 2019-2022 OpenCFD Ltd. +# Copyright (C) 2019-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -26,7 +26,8 @@ # -j | -jN | -j N # # Parsed options (wmake) -# -debug +# -debug | -debug-O[g0123] +# -strict # -q | -queue # -build-root=... # Exports FOAM_BUILDROOT value. @@ -87,7 +88,7 @@ USAGE #------------------------------------------------------------------------------ unset wmakeOpt_frontend wmakeOpt_nonRecursive -unset wmakeOpt_debug wmakeOpt_log wmakeOpt_queue +unset wmakeOpt_debug wmakeOpt_log wmakeOpt_strict wmakeOpt_queue for arg in "$@" do @@ -178,6 +179,11 @@ do continue # Argument handled, remove it ;; + -strict) + wmakeOpt_strict="$arg" + continue # Argument handled, remove it + ;; + -q | -queue) wmakeOpt_queue="-queue" continue # Argument handled, remove it @@ -203,13 +209,13 @@ then if [ -z "$wmakeOpt_log" ] then exec wmake $wmakeOpt_frontend -all \ - $wmakeOpt_debug $wmakeOpt_queue $wmakeOpt_openmp $* + $wmakeOpt_debug $wmakeOpt_strict $wmakeOpt_queue $wmakeOpt_openmp $* exit $? # Unneeded, but just in case something went wrong else echo "Logging wmake -all output to '$wmakeOpt_log'" 1>&2 echo 1>&2 exec wmake $wmakeOpt_frontend -all \ - $wmakeOpt_debug $wmakeOpt_queue $wmakeOpt_openmp $* 2>&1 | \ + $wmakeOpt_debug $wmakeOpt_strict $wmakeOpt_queue $wmakeOpt_openmp $* 2>&1 | \ /usr/bin/tee $wmakeOpt_log # Need to cleanup after the tee rc=$? # Error code from tee (not wmake), but not entirely important @@ -234,7 +240,7 @@ fi #------------------------------------------------------------------------------ unset wmakeOpt_frontend wmakeOpt_nonRecursive -unset wmakeOpt_debug wmakeOpt_log wmakeOpt_queue +unset wmakeOpt_debug wmakeOpt_log wmakeOpt_strict wmakeOpt_queue unset -f usage diff --git a/wmake/wmake b/wmake/wmake index 805f575b98..1c6aef2477 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -7,7 +7,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2017-2022 OpenCFD Ltd. +# Copyright (C) 2017-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -71,6 +71,7 @@ then cat<&2 @@ -520,6 +525,22 @@ case "$opt_openfoam" in ;; esac +# Handle -strict flag(s) +if [ -n "$opt_strict" ] +then + # Add +strict into WM_COMPILE_CONTROL + opt_strict="${WM_COMPILE_CONTROL:+ }+strict" + case "$WM_COMPILE_CONTROL" in + (*+strict*) + # Appears to have already been added + ;; + (*) + export WM_COMPILE_CONTROL="${WM_COMPILE_CONTROL}${opt_strict}" + ;; + esac +fi + + # Debug: ##echo "WM_COMPILE_CONTROL='$WM_COMPILE_CONTROL'" 1>&2