Bug 22953 – impossible to test for pragma support

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-28T22:58:56Z
Last change time
2024-12-13T19:21:52Z
Assigned to
No Owner
Creator
Adam D. Ruppe
See also
https://issues.dlang.org/show_bug.cgi?id=19110
Moved to GitHub: dmd#20077 →

Comments

Comment #0 by destructionator — 2022-03-28T22:58:56Z
It is impossible to test if a given pragma is supported in D. __traits(compiles) doesn't work since a pragma is not an expression, and wrapping it in a function can fail because some pragmas can only be used top level. This makes writing code that supports multiple versions of the compiler unnecessarily difficult.
Comment #1 by aldacron — 2022-03-29T03:37:59Z
What about `static if(__VERSION__ >= XXXX)`?
Comment #2 by destructionator — 2022-03-29T11:30:57Z
That fails in the event of backported features that didn't bump the version number (see some in gdc), and in the event of target-specific pragmas, like `linkerDirective`, which only applies if using a MS-COFF target. For that one, you can approximate it it with a combination of static if version > X and version(cruntime_microsoft), but you can target ms-coff with the mingw runtime too, so this check isn't really correct. If there was a version(Object_format_COFF) that'd possibly work for this case too but there isn't one The best way would be something like __traits(supportsPragma, "") to check it directly, then you can static if it out. (though since pragmas are often attached to declarations, that's easier said than done in general, it'd at least give you the starting point as a reliable test.)
Comment #3 by ibuclaw — 2022-03-29T15:57:27Z
(In reply to Mike Parker from comment #1) > What about `static if(__VERSION__ >= XXXX)`? Different vendors support different pragmas.
Comment #4 by robert.schadek — 2024-12-13T19:21:52Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20077 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB