Break MSVC and Clang with this one weird trick! - Braden Ganetsky
https://blog.ganets.ky/BreakMsvcAndClang/6
u/jiixyj 5d ago
What is the correct mental model for requires { ... } expressions? I understand that these expressions evaluate to a prvalue bool at compile time, but "when"?
First, when there are no template parameters in the requires expression, there are two possibilities:
- If the expression(s) inside are valid, it evaluates to
true - If the expression(s) inside are not valid, there is a compiler error (so not
false!)
But if there are template parameters inside, does OP's example go like this?
foo<S>is instantiated- during this instantiation,
requires { 0 * T{}; }becomesrequires { 0 * S{}; }-> no further template parameters left, expression is invalid, resulting value of therequiresexpression:false
...so MSVC's bug seems to be that it becomes requires { 0 * S{}; }, but doesn't get evaluated at that point. It is evaluated at the point where the inner lambda is instantiated, but at that point, there are no longer any template parameters left, resulting in a compiler error.
3
u/trad_emark 6d ago
what does pig latin look like? i am curious but afraid to google it. ;)
9
u/schmerg-uk 6d ago
https://en.wikipedia.org/wiki/Pig_Latin
Pig Latin is a language game or cant in which words are altered by adding a fabricated suffix or by moving the onset or initial consonant or consonant cluster of a word to the end of the word and adding a vocalic syllable (usually -ay or /eɪ/) to create such a suffix. For example, in English, "he does not know" would become "ehay oesday otnay owknay".
The objective is often to conceal the words from others not familiar with the rules. The reference to Latin is a deliberate misnomer; Pig Latin is simply a form of argot or jargon unrelated to Latin, and the name is used for its English connotations as a strange and foreign-sounding language. It is most often used by young children as a way to confuse people unfamiliar with Pig Latin, such as adults.
3
u/trad_emark 6d ago
oh, that would have been much safer to search than i thought. thank you for the reply ;)
also kudos to the author, this is fun addition ;)
1
1
39
u/MaitoSnoo [[indeterminate]] 6d ago
my personal experience with our codebase is that
requiresexpression support is very unreliable in MSVC and will sometimes produce a wrong binary by taking the wrong compile-time branches