Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
Qt 5 provides a macro for this context which expands to either 'const' or 'constexpr' depending on whether cxx_constexpr is available, and another macro which expands to either 'const' or 'constexpr' depending on whether cxx_relaxed_constexpr is available. Thinking of it, since C++14 constexpr does not imply const anymore, so isn't this macro ambiguous wrt standard c++ ? On Wed, Jul 8, 2015 at 10:42 PM, Stephen Kelly steve...@gmail.com wrote: Jean-Michaël Celerier wrote: I think there should be a test for the different allowed contexts of the ${prefix_arg}_RELAXED_CONSTEXPR and ${prefix_arg}_CONSTEXPR macros. Could you extend Tests/Module/WriteCompilerDetectionHeader with a test for that? For sure, I'll do this asap. Great, thanks! Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
Jean-Michaël Celerier wrote: Qt 5 provides a macro for this context which expands to either 'const' or 'constexpr' depending on whether cxx_constexpr is available, and another macro which expands to either 'const' or 'constexpr' depending on whether cxx_relaxed_constexpr is available. Thinking of it, since C++14 constexpr does not imply const anymore, so isn't this macro ambiguous wrt standard c++ ? The 'const' keyword can be used in multiple contexts. Can you clarify which you mean with a reference to some document? Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
I'm referring to the const used after methods (struct { int f() const; }). Here is an example : https://ideone.com/C28SMn Best regards :) On Mon, Aug 3, 2015 at 7:20 PM, Stephen Kelly steve...@gmail.com wrote: Jean-Michaël Celerier wrote: Qt 5 provides a macro for this context which expands to either 'const' or 'constexpr' depending on whether cxx_constexpr is available, and another macro which expands to either 'const' or 'constexpr' depending on whether cxx_relaxed_constexpr is available. Thinking of it, since C++14 constexpr does not imply const anymore, so isn't this macro ambiguous wrt standard c++ ? The 'const' keyword can be used in multiple contexts. Can you clarify which you mean with a reference to some document? Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
[cmake-developers] [PATCH] Macro generation for relaxed constexpr
Hello, At the ned of this mail is a patch that adds generation of a macro for the relaxed (c++14) constexpr in WriteCompilerDetectionHeader. This is intended for compilers that support c++11 constexpr (with everything on a single return statement) like GCC-4.9 and the upcoming MSVC, but not extended constexpr which allows for more complete functions. This way, code bases can reap the benefits of most recent compilers at no cost. Best regards Jean-Michaël Celerier diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake index a3b73bb..f7af7ec 100644 --- a/Modules/WriteCompilerDetectionHeader.cmake +++ b/Modules/WriteCompilerDetectionHeader.cmake @@ -144,6 +144,7 @@ # == === = # ``c_restrict`` ``PREFIX_RESTRICT`` ``restrict`` # ``cxx_constexpr`` ``PREFIX_CONSTEXPR`` ``constexpr`` +# ``cxx_relaxed_constexpr`` ``PREFIX_RELAXED_CONSTEXPR`` ``constexpr`` # ``cxx_deleted_functions`` ``PREFIX_DELETED_FUNCTION`` ``= delete`` # ``cxx_extern_templates````PREFIX_EXTERN_TEMPLATE````extern`` # ``cxx_final`` ``PREFIX_FINAL`` ``final`` @@ -494,6 +495,16 @@ function(write_compiler_detection_header # endif \n) endif() + if (feature STREQUAL cxx_relaxed_constexpr) +set(def_value ${prefix_arg}_RELAXED_CONSTEXPR) +set(file_content ${file_content} +# if ${def_name} +#define ${def_value} constexpr +# else +#define ${def_value} +# endif +\n) + endif() if (feature STREQUAL cxx_final) set(def_value ${prefix_arg}_FINAL) set(file_content ${file_content} -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
Jean-Michaël Celerier wrote: I think there should be a test for the different allowed contexts of the ${prefix_arg}_RELAXED_CONSTEXPR and ${prefix_arg}_CONSTEXPR macros. Could you extend Tests/Module/WriteCompilerDetectionHeader with a test for that? For sure, I'll do this asap. constexpr foo = ...; If I read http://en.cppreference.com/w/cpp/language/constexpr correctly, there should be no differences in variable handling between C++11 and 14 for constexpr, the changes are only for function bodies. Right. Qt 5 provides a macro for this context which expands to either 'const' or 'constexpr' depending on whether cxx_constexpr is available, and another macro which expands to either 'const' or 'constexpr' depending on whether cxx_relaxed_constexpr is available. Compare the assembly of the following when compiled with -std=c++98/11/14: #if __has_feature(cxx_constexpr) #define DECL_CONSTEXPR constexpr #else #define DECL_CONSTEXPR #endif #if __has_feature(cxx_relaxed_constexpr) #define DECL_RELAXED_CONSTEXPR constexpr #else #define DECL_RELAXED_CONSTEXPR #endif DECL_CONSTEXPR int getNumRegular() { return 42; } DECL_RELAXED_CONSTEXPR int getNumRelaxed() { int result = 0; for (int i = 0; i 4; ++i) result += 10; return result + 2; } DECL_CONSTEXPR int betterIfConstexprParameter(int param) { return param / 2; } #if __has_feature(cxx_constexpr) #define CXX11_CONSTEXPR_VARIABLE constexpr #else #define CXX11_CONSTEXPR_VARIABLE const #endif #if __has_feature(cxx_relaxed_constexpr) #define CXX14_CONSTEXPR_VARIABLE constexpr #else #define CXX14_CONSTEXPR_VARIABLE const #endif int main() { CXX11_CONSTEXPR_VARIABLE int num1 = getNumRegular(); CXX11_CONSTEXPR_VARIABLE int result1 = betterIfConstexprParameter(num1); CXX14_CONSTEXPR_VARIABLE int num2 = getNumRelaxed(); CXX14_CONSTEXPR_VARIABLE int result2 = betterIfConstexprParameter(num2); return result1 - result2; } $ wc -l 98.s 11.s 14.s 126 98.s 90 11.s 31 14.s Of course, such macros don't belong in the same patch as the one you submitted and could be in a follow-up. Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
Jean-Michaël Celerier wrote: Hello, At the ned of this mail is a patch that adds generation of a macro for the relaxed (c++14) constexpr in WriteCompilerDetectionHeader. Thanks for working on this. I have some thoughts for archival purposes on the mailing list. These aren't things you necessarily need to address: * I think I've read about constexpr being made even more relaxed in a future CXX standard. Would we then call it 'yet_more_relaxed_constexpr'? Clang, whose names CMake follows, likely won't introduce a name for it because it will likely start to rely on SD-6 macros instead of extending __has_feature. SD-6 doesn't have that problem because it would just use a new value for the __cpp_constexpr macro (which already has two possible values 200704 and 201304). * The 'relaxed' name is already what is currently used for this feature. Future developments don't really matter. * It's appropriate for this macro to expand to empty if cxx_relaxed_constexpr is not available, because a function marked constexpr which is only cxx11-constexpr but not cxx14-constexpr will fail to compile anyway. Programmers are aware of ways to implement methods in a way that is cxx11-constexpr, even if making it cxx14-constexpr would be more easy/readable. * A method marked constexpr will fail to compile with a compiler which does not support relaxed constexpr if the method uses language which requires relaxed mode (such as a for loop), even if the method is evaluated in a non- constant expression. I tested GCC and Clang. So assuming all that is correct, I think this patch is good. I think there should be a test for the different allowed contexts of the ${prefix_arg}_RELAXED_CONSTEXPR and ${prefix_arg}_CONSTEXPR macros. Could you extend Tests/Module/WriteCompilerDetectionHeader with a test for that? Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
I think there should be a test for the different allowed contexts of the ${prefix_arg}_RELAXED_CONSTEXPR and ${prefix_arg}_CONSTEXPR macros. Could you extend Tests/Module/WriteCompilerDetectionHeader with a test for that? For sure, I'll do this asap. constexpr foo = ...; If I read http://en.cppreference.com/w/cpp/language/constexpr correctly, there should be no differences in variable handling between C++11 and 14 for constexpr, the changes are only for function bodies. Jean-Michaël On Wed, Jul 8, 2015 at 9:49 PM, Stephen Kelly steve...@gmail.com wrote: Stephen Kelly wrote: * A method marked constexpr will fail to compile with a compiler which does not support relaxed constexpr if the method uses language which requires relaxed mode (such as a for loop), even if the method is evaluated in a non- constant expression. I tested GCC and Clang. Are there any values of '...' where constexpr foo = ...; would compile or not depending only on whether using cxx11-constexpr or cxx14-constexpr? Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Macro generation for relaxed constexpr
Stephen Kelly wrote: * A method marked constexpr will fail to compile with a compiler which does not support relaxed constexpr if the method uses language which requires relaxed mode (such as a for loop), even if the method is evaluated in a non- constant expression. I tested GCC and Clang. Are there any values of '...' where constexpr foo = ...; would compile or not depending only on whether using cxx11-constexpr or cxx14-constexpr? Thanks, Steve. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers