Objection! A Language Lawyer Story
Objection! A Language Lawyer Story
— Sy Brand (@TartanLlama) July 16, 2020
🔊 for my awful voice acting pic.twitter.com/GmZqQShtEG
元ネタ:ゲーム「逆転裁判シリーズ」(英語版は"Ace Attorney")より。プログラミング言語仕様に基づいて議論する人々は、俗に 言語法律家(language lawyer) とよばれる。
登場人物(括弧内は日本語版でのキャラクタ名):
- Phoenix Wright(成歩堂 龍一; なるほどう りゅういち), Nick1
- Miles Edgeworth(御剣 怜侍; みつるぎ れいじ)
- Maya Fey(綾里 真宵; あやさと まよい)
- Judge(裁判長)
Script
Phoenix: I would like to present to the compiler: this code.
struct foo{};
constexpr foo x;
int main() {
[]{ return x; }();
}
Phoenix: As you can see, it should compile...
[Objection!]
Edgeworth: You fool.
Phoenix: Oh? You've found a problem?
Edgeworth: You forget to initialize x.
[Take that!]
Phoenix: You're wrong!
Phoenix: [class.ctor.default]/42 says the default constructor satisfies the conditions for a constexpr constructor!
Edgeworth: Impossible!
Gallery: He's right!
Judge: Order!
Judge: I'm afraid the defense is correct. I think this code should compile...
[Hold it!]
Edgeworth: You almost had me there, Wright.
Phoenix: Does this mean you found something else?
Edgeworth: Look at the lambda.
Edgeworth: You forgot to capture x!
Phoenix: What!? No!
Judge: You're quite right there!
Judge: I'm ready to issue my verdict. This code shouldn't compile...
[Hold it!]
Maya: .........
Maya: You've got this, Nick, just look at the standard.
Phoenix: I've got to bluff while I find the right paragraph.
Phoenix: If you look at [expr.prim.lambda.capture]...
Edgeworth: That section is massive, show me the paragraph!
Phoenix: I found it!
Phoenix: If you look at paragraph 8 you'll see...
Phoenix: that you don't need to capture entities which are not odr-used!
[Objection!]
Edgeworth: But x is odr-used!
[Objection!]
Phoenix: No, because it's constexpr!
Edgeworth: ...NO!!!
Judge: Can someone explain what odr-use is?
Phoenix: It's when you use a variable in a way which requires a definition.
Phoenix: [basic.def.odr]/4.2 says this code with a constexpr variable does not constitute odr-use.
Judge: Is this right, Edgeworth?
Edgeworth: .........
Judge: I'll take that as a yes.
Judge: I can now judge that this code...
Judge: Compiles.