- What does operating on raw bytes mean in a C++ context? - 1 Update
- Instantiating a template function inside a false if constexpr - 8 Updates
- Double reference - 2 Updates
- Exercises (was Re: Range-based for loops when ...) - 2 Updates
- sizeof(bitfield struct) - 4 Updates
- How to print instances of my classes - 1 Update
- How to print instances of my classes - 4 Updates
- neoGFX C++ ECS - 1 Update
- spurious warning? - 1 Update
- Module libraries - 1 Update
Robert Wessel <robertwessel2@yahoo.com>: Nov 07 09:18AM -0600 On Tue, 6 Nov 2018 07:13:37 -0000 (UTC), Juha Nieminen >> come to mind immediately. >Does it even have a modern C++ compiler? Does anybody even know how to use >such a thing? IFAIK, it does not. It does have a C89 compiler. There are also some DSPs still out there with CHAR_BIT as 16 or 32. |
Juha Nieminen <nospam@thanks.invalid>: Nov 07 10:06AM Is this a bug in clang, or is this intended behavior? Consider the following program: //----------------------------------------------------------------- #include <iostream> template<typename... Params_t> constexpr int constexprValue(Params_t...) { return 5; } int main() { const bool flag = true; if constexpr(flag) { constexpr int value = constexprValue(1, 2, 3); std::cout << value << "\n"; } } //----------------------------------------------------------------- This compiles and works fine. However, change flag to false, and clang gives an error: error: constexpr variable 'value' must be initialized by a constant expression undefined function 'constexprValue<int, int, int>' cannot be used in a constant expression It must be a bug, right? Because if it's intended, it's incomprehensible why they would want that to fail. |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Nov 07 11:08AM On Wed, 7 Nov 2018 10:06:32 -0000 (UTC) > in a constant expression > It must be a bug, right? Because if it's intended, it's incomprehensible > why they would want that to fail. Your code works for me with clang-7.0.0 and gcc-8.2.0 with the -std=c++17 compiler flag. constexprValue() is defined whether or not 'flag' evaluates to false or true and is instantiated here for literal types, and 'flag' is initialized by a literal, so I think it must be a bug. |
"Öö Tiib" <ootiib@hot.ee>: Nov 07 03:10AM -0800 On Wednesday, 7 November 2018 12:06:42 UTC+2, Juha Nieminen wrote: > in a constant expression > It must be a bug, right? Because if it's intended, it's incomprehensible > why they would want that to fail. Yes, it is most probably a bug. It compiles with clang 3.9 , with clangs 4, 5 and 6 it fails and with 7 it compiles again. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 07 12:40PM +0100 On 07.11.2018 11:06, Juha Nieminen wrote: > expression > undefined function 'constexprValue<int, int, int>' cannot be used > in a constant expression Unable to reproduce with g++ and msvc. > It must be a bug, right? Because if it's intended, it's incomprehensible > why they would want that to fail. Agreed. But consider: ------------------------------------------------------------------------- #include <iostream> using namespace std; template< class > struct Baluba; template<> struct Baluba<int>{}; // Defined. template< int x > void foo() { if constexpr( x == 666 ) { Baluba<double> bah; } } void call_foo() { foo<42>(); // OK #ifdef FOO foo<666>(); // Ungood, doesn't compile.
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment