Home » Community » U++ community news and announcements » 2024rc1
Re: 2024rc1 [message #61041 is a reply to message #61039] |
Mon, 21 October 2024 18:12   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
mirek wrote on Mon, 21 October 2024 08:45Lance wrote on Mon, 21 October 2024 13:01
A compiler that encounters a non-constexpr if-statement with a constexpr conditional may issue a warning advising you to use if constexpr instead. This will ensure that compile-time evaluation will occur (even if optimizations are disabled).
Well, thinking about it, I guess actually the real benefit for me would be something else: compiler issues an error if the expression you marked constexpr is not...
Agreed. Like "override", make a programmer's intention more explicit, and do, more important than but similar, compiler check when it doesn't going as claimed by the programmer.
Reminds me of a related case, where constexpr seems to be helpful or possibly necessary.
union Flags{
int32 dummy;
struct{
byte borderLeft :3;
byte borderRight :3;
byte borderTop :3;
byte borderBottom:3;
byte halign :2;
byte valign :2; //16th bit
bool faceNotNull :1;
bool boldNotNull :1;
bool heightNotNull :1;
bool widthNotNull :1;
bool underlineNotNull:1;
bool italicNotNull :1;
bool strikeoutNotNull:1; //23rd bit
};
constexpr Flags() : dummy(0){ static_assert(sizeof(*this)==sizeof(dummy)); }
static constexpr int32 FontMask()
{
Flags f;
f.faceNotNull = true;
f.boldNotNull = true;
f.heightNotNull = true;
f.widthNotNull = true;
f.underlineNotNull = true;
f.italicNotNull = true;
f.strikeoutNotNull = true;
return f.dummy;
}
};
It's a somewhat contrived example. I am not sure ,for int32 FontMask(), if I don't it constexpr, will the code be compiled same as if I do. It's totally possible they do with todays smart and agressive as crazy compiler optimization.
|
|
|
 |
|
2024rc1
By: mirek on Sat, 28 September 2024 09:16
|
 |
|
Re: 2024rc1
By: Tom1 on Sat, 28 September 2024 18:36
|
 |
|
Re: 2024rc1
By: JeyCi on Sat, 28 September 2024 19:21
|
 |
|
Re: 2024rc1
By: mirek on Sun, 29 September 2024 20:51
|
 |
|
Re: 2024rc1
By: Didier on Sat, 28 September 2024 20:50
|
 |
|
Re: 2024rc1
By: Tom1 on Sat, 28 September 2024 22:55
|
 |
|
Re: 2024rc1
By: mirek on Sun, 29 September 2024 20:55
|
 |
|
Re: 2024rc1
By: Tom1 on Sun, 29 September 2024 22:02
|
 |
|
Re: 2024rc1
By: mirek on Sun, 29 September 2024 23:14
|
 |
|
Re: 2024rc1
By: Lance on Mon, 30 September 2024 01:02
|
 |
|
Re: 2024rc1
By: mirek on Mon, 30 September 2024 12:01
|
 |
|
Re: 2024rc1
By: Tom1 on Mon, 30 September 2024 12:06
|
 |
|
Re: 2024rc1
By: Tom1 on Mon, 30 September 2024 15:37
|
 |
|
Re: 2024rc1
By: Lance on Sat, 12 October 2024 17:31
|
 |
|
Re: 2024rc1
By: Lance on Sat, 12 October 2024 20:20
|
 |
|
Re: 2024rc1
By: Lance on Sun, 13 October 2024 06:10
|
 |
|
Re: 2024rc1
By: mirek on Sun, 13 October 2024 07:52
|
 |
|
Re: 2024rc1
By: Lance on Sun, 13 October 2024 13:28
|
 |
|
Re: 2024rc1
By: mirek on Sun, 13 October 2024 13:55
|
 |
|
Re: 2024rc1
By: Lance on Sun, 13 October 2024 14:20
|
 |
|
Re: 2024rc1
By: mirek on Sun, 13 October 2024 13:58
|
 |
 |
Re: 2024rc1
By: Lance on Sun, 13 October 2024 14:23
|
 |
|
Re: 2024rc1
By: mirek on Mon, 14 October 2024 16:17
|
 |
|
Re: 2024rc1
By: Lance on Mon, 14 October 2024 17:09
|
 |
|
Re: 2024rc1
By: mirek on Tue, 15 October 2024 07:40
|
 |
|
Re: 2024rc1
By: mirek on Mon, 14 October 2024 16:13
|
 |
|
Re: 2024rc1
By: Lance on Mon, 14 October 2024 16:23
|
 |
|
Re: 2024rc1
By: mirek on Mon, 14 October 2024 16:42
|
 |
|
Re: 2024rc1
By: Lance on Mon, 14 October 2024 17:21
|
 |
|
Re: 2024rc1
By: mirek on Tue, 15 October 2024 13:31
|
 |
|
Re: 2024rc1
By: Lance on Tue, 15 October 2024 15:18
|
 |
|
Re: 2024rc1
By: mirek on Thu, 17 October 2024 10:47
|
 |
|
Re: 2024rc1
By: Lance on Thu, 17 October 2024 21:01
|
 |
|
Re: 2024rc1
By: Lance on Mon, 21 October 2024 02:11
|
 |
|
Re: 2024rc1
By: Lance on Mon, 21 October 2024 02:27
|
 |
|
Re: 2024rc1
By: mirek on Mon, 21 October 2024 09:05
|
 |
|
Re: 2024rc1
By: Lance on Mon, 21 October 2024 12:55
|
 |
|
Re: 2024rc1
By: Lance on Mon, 21 October 2024 13:01
|
 |
|
Re: 2024rc1
By: mirek on Mon, 21 October 2024 13:21
|
 |
|
Re: 2024rc1
By: mirek on Mon, 21 October 2024 14:45
|
 |
|
Re: 2024rc1
By: Lance on Mon, 21 October 2024 18:12
|
 |
|
Re: 2024rc1
By: Lance on Wed, 16 October 2024 00:11
|
 |
|
Re: 2024rc1
By: mirek on Wed, 16 October 2024 11:30
|
 |
 |
Re: 2024rc1
By: Lance on Wed, 16 October 2024 15:18
|
 |
|
Re: 2024rc1
By: Oblivion on Sun, 13 October 2024 09:53
|
 |
|
Re: 2024rc1
By: mirek on Mon, 14 October 2024 15:36
|
Goto Forum:
Current Time: Thu Aug 14 00:27:49 CEST 2025
Total time taken to generate the page: 0.08236 seconds
|