constexpr int fn1() {
if constexpr (std::is_constant_evaluated()) // condition is always true! return 0; else return 1;
}
constexpr int fn2() {
if (std::is_constant_evaluated()) return 0; else return 1;
}
Solves PR42977
Differential D69518
[Diagnostics] Warn for std::is_constant_evaluated in constexpr mode xbolva00 on Oct 28 2019, 10:25 AM. Authored by
Details constexpr int fn1() { if constexpr (std::is_constant_evaluated()) // condition is always true! return 0; else return 1; } constexpr int fn2() { if (std::is_constant_evaluated()) return 0; else return 1; } Solves PR42977
Diff Detail
Event Timeline
Comment Actions This broke two stage builds of libc++. Can we revert this until a fix is ready? FAIL: libc++ :: std/utilities/meta/meta.const.eval/is_constant_evaluated.fail.cpp (55845 of 59103) ******************** TEST 'libc++ :: std/utilities/meta/meta.const.eval/is_constant_evaluated.fail.cpp' FAILED ******************** Command: ['/p/tllvm/bin/clang++', '-o', '/dev/null', '-x', 'c++', '/home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.fail.cpp', '-c', '-v', '-ftemplate-depth=270', '-fsyntax-only', '-Xclang', '-verify', '-Xclang', '-verify-ignore-unexpected=note', '-ferror-limit=1024', '-Werror=thread-safety', '-std=c++2a', '-include', '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', '-I/home/dave/s/lp/libcxx/include', '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', '-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="/home/dave/s/lp/libcxx/test/std/input.output/filesystems/Inputs/static_test_env"', '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="/tmp/_update_lc/t/projects/libcxx/test/filesystem/Output/dynamic_env"', '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="/usr/bin/python /home/dave/s/lp/libcxx/test/support/filesystem_dynamic_test_helper.py"', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move', '-Wno-c++11-extensions', '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-Wno-error=user-defined-warnings', '-c'] Exit Code: 1 Standard Error: -- clang version 10.0.0 (/home/dave/s/lp/clang 7e1a3076419d4d453d71143a1e81409ea1db177c) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /p/tllvm/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 "/p/tllvm/bin/clang-10" -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -disable-llvm-verifier -discard-value-names -main-file-name is_constant_evaluated.fail.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -nostdinc++ -resource-dir /p/tllvm/lib64/clang/10.0.0 -include /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I /home/dave/s/lp/libcxx/include -I /tmp/_update_lc/t/projects/libcxx/include/c++build -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -I /home/dave/s/lp/libcxx/test/support -D "LIBCXX_FILESYSTEM_STATIC_TEST_ROOT=\"/home/dave/s/lp/libcxx/test/std/input.output/filesystems/Inputs/static_test_env\"" -D "LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT=\"/tmp/_update_lc/t/projects/libcxx/test/filesystem/Output/dynamic_env\"" -D "LIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER=\"/usr/bin/python /home/dave/s/lp/libcxx/test/support/filesystem_dynamic_test_helper.py\"" -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem /usr/local/include -internal-isystem /p/tllvm/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror=thread-safety -Wall -Wextra -Werror -Wuser-defined-warnings -Wshadow -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-error=user-defined-warnings -std=c++2a -fdeprecated-macro -fdebug-compilation-dir /tmp/_update_lc/t -ftemplate-depth 270 -ferror-limit 1024 -fmessage-length 0 -fgnuc-version=4.2.1 -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -verify -verify-ignore-unexpected=note -faddrsig -x c++ /home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.fail.cpp clang -cc1 version 10.0.0 based upon LLVM 10.0.0svn default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /home/dave/s/lp/libcxx/include /tmp/_update_lc/t/projects/libcxx/include/c++build /home/dave/s/lp/libcxx/test/support /usr/local/include /p/tllvm/lib64/clang/10.0.0/include /usr/include End of search list. error: 'error' diagnostics seen but not expected: File /home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.fail.cpp Line 26: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression 1 error generated. -- Expected compilation using verify to pass! ******************** FAIL: libc++ :: std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp (55846 of 59103) ******************** TEST 'libc++ :: std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp' FAILED ******************** Command: ['/p/tllvm/bin/clang++', '-o', '/tmp/_update_lc/t/projects/libcxx/test/std/utilities/meta/meta.const.eval/Output/is_constant_evaluated.pass.cpp.o', '-x', 'c++', '/home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp', '-c', '-v', '-ftemplate-depth=270', '-Werror=thread-safety', '-std=c++2a', '-include', '/home/dave/s/lp/libcxx/test/support/nasty_macros.h', '-nostdinc++', '-I/home/dave/s/lp/libcxx/include', '-I/tmp/_update_lc/t/projects/libcxx/include/c++build', '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-I/home/dave/s/lp/libcxx/test/support', '-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="/home/dave/s/lp/libcxx/test/std/input.output/filesystems/Inputs/static_test_env"', '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="/tmp/_update_lc/t/projects/libcxx/test/filesystem/Output/dynamic_env"', '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="/usr/bin/python /home/dave/s/lp/libcxx/test/support/filesystem_dynamic_test_helper.py"', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move', '-Wno-c++11-extensions', '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c'] Exit Code: 1 Standard Error: -- clang version 10.0.0 (/home/dave/s/lp/clang 7e1a3076419d4d453d71143a1e81409ea1db177c) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /p/tllvm/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 "/p/tllvm/bin/clang-10" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name is_constant_evaluated.pass.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -nostdinc++ -resource-dir /p/tllvm/lib64/clang/10.0.0 -include /home/dave/s/lp/libcxx/test/support/nasty_macros.h -I /home/dave/s/lp/libcxx/include -I /tmp/_update_lc/t/projects/libcxx/include/c++build -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -I /home/dave/s/lp/libcxx/test/support -D "LIBCXX_FILESYSTEM_STATIC_TEST_ROOT=\"/home/dave/s/lp/libcxx/test/std/input.output/filesystems/Inputs/static_test_env\"" -D "LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT=\"/tmp/_update_lc/t/projects/libcxx/test/filesystem/Output/dynamic_env\"" -D "LIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER=\"/usr/bin/python /home/dave/s/lp/libcxx/test/support/filesystem_dynamic_test_helper.py\"" -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -internal-isystem /usr/local/include -internal-isystem /p/tllvm/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror=thread-safety -Wall -Wextra -Werror -Wuser-defined-warnings -Wshadow -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -std=c++2a -fdeprecated-macro -fdebug-compilation-dir /tmp/_update_lc/t/projects/libcxx/test/std/utilities/meta/meta.const.eval -ftemplate-depth 270 -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -faddrsig -o /tmp/_update_lc/t/projects/libcxx/test/std/utilities/meta/meta.const.eval/Output/is_constant_evaluated.pass.cpp.o -x c++ /home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp clang -cc1 version 10.0.0 based upon LLVM 10.0.0svn default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /home/dave/s/lp/libcxx/include /tmp/_update_lc/t/projects/libcxx/include/c++build /home/dave/s/lp/libcxx/test/support /usr/local/include /p/tllvm/lib64/clang/10.0.0/include /usr/include End of search list. /home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp:35:24: error: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Werror,-Wconstant-evaluated] constexpr bool p = std::is_constant_evaluated(); ^ /home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp:41:19: error: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Werror,-Wconstant-evaluated] static_assert(std::is_constant_evaluated(), ""); ^ /home/dave/s/lp/libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp:44:33: error: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Werror,-Wconstant-evaluated] ASSERT_SAME_TYPE(InTemplate<std::is_constant_evaluated()>, InTemplate<true>); ^ 3 errors generated. -- Compilation failed unexpectedly! ******************** Testing Time: 111.41s ******************** Failing Tests (2): libc++ :: std/utilities/meta/meta.const.eval/is_constant_evaluated.fail.cpp libc++ :: std/utilities/meta/meta.const.eval/is_constant_evaluated.pass.cpp Expected Passes : 43344 Expected Failures : 103 Unsupported Tests : 15654 Unexpected Failures: 2 Comment Actions Line 918 Add: to libcxx/utils/libcxx/test/config.py Can you please try? cc @EricWF |
"constexpr mode" isn't a thing. Maybe just "in this context"?
I think this should have its own warning group, not be grouped under -Wtautological-compare.