Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » 2024rc1
Re: 2024rc1 [message #61041 is a reply to message #61039] Mon, 21 October 2024 18:12 Go to previous messageGo to previous message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
mirek wrote on Mon, 21 October 2024 08:45
Lance 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.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon14.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message icon14.gif
Read Message
Read Message
Previous Topic: Win32 openssl updated to 3.2.1 version
Next Topic: SetRect "MegaRect" support...
Goto Forum:
  


Current Time: Thu Aug 14 00:27:49 CEST 2025

Total time taken to generate the page: 0.08236 seconds