diff --git a/applications/test/Dictionary/Test-Dictionary.C b/applications/test/Dictionary/Test-Dictionary.C index 41d772ecb8a98cb8333e792b6f868fe350cb4621..7238260ba57f4101775f2a10c656955446e9c10f 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<ent>, dict, iter) + forAllConstIters(dict, iter) { Info<< "element : " << *iter; } @@ -153,9 +153,9 @@ int main(int argc, char *argv[]) } Info<< nl << "scalarDict1: " << endl; - forAllConstIter(PtrDictionary<Scalar>, scalarDict, iter) + forAllConstIters(scalarDict, iter) { - Info<< " = " << iter() << endl; + Info<< " = " << *iter << endl; } PtrDictionary<Scalar> 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<Scalar>, 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 a0ed48b862c8cd85e8f2ff99f85ccf12071e93cb..4418b4e18cefa681ca812d91f34ff4d05e7afb71 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<ent>, 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 4acbd5e747bdff4b04033de84d84602c5c1bc5ce..8eabd24fb16032c005938ec74b5a2ef1296bd136 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<IFstreamDelayed&>(*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 e4cb5fb72d35664b1d40b1b16f7fa0a77c85b2d0..9151a94faff42b0f1e8d4cc6cfd19b725bed81a6 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 c53d6a48a4c376273e0b3a8a7ee77e69f3cf0d17..f05ed408104e8f6b4ed1b79e7b800d17b18dc621 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 19f5849746061483cc3222a8e7c2ef7e8a5bd37f..079505d3ddf87ed52a3d5c7aeccd8e032ad398f0 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 1f986544e6a5b2bd9322f303b2a6650e39eef126..55b25b34d5e0888f0c913148ae5c67342765d70c 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 049b28b780aa6da506febf21fe72853f4051357c..b3ae8e8218cd8d26d7a51a584a1599d764b86e79 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 93fe183f02fcde00376dafd65089b60414ad4288..0f5ddeea8e3c2e8b56f39e88642d89583f20d981 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 805f575b98d5f32521b16ec6c3c4af92f6b5cd2b..1c6aef24770be4dbefc8e30fd044270112a28066 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<<HELP_FULL -debug Add '-g -DFULLDEBUG' flags -debug-O[g0123] Add '-g -DFULLDEBUG' flags and optimization level + -strict More deprecation warnings ('+strict' WM_COMPILE_CONTROL) -build-root=PATH Specify FOAM_BUILDROOT for compilation intermediates -module-prefix=PATH Specify FOAM_MODULE_PREFIX as absolute/relative path -module-prefix=TYPE Specify FOAM_MODULE_PREFIX as predefined type @@ -209,7 +210,7 @@ allCores() # Default to compiling the local target only unset opt_all opt_update opt_quiet opt_show opt_pwd -unset opt_debug opt_openmp opt_openfoam +unset opt_debug opt_openmp opt_openfoam opt_strict # Consistency with inherited values if [ "$WM_QUIET" = true ] @@ -267,6 +268,10 @@ do opt_debug="-g -${1##*-}" ;; + -strict) + opt_strict="+strict" + ;; + -build-root=*) export FOAM_BUILDROOT="${1#*=}" echo "Build-root = ${FOAM_BUILDROOT:-[]}" 1>&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