Dan Piponi on Nostr: Here's C++ playing a nasty trick on me: class A { static constexpr int X = 1; }; ...
Here's C++ playing a nasty trick on me:
class A
{
static constexpr int X = 1;
};
template<int X>
class B : public A
{
static_assert(X == 1);
};
int main()
{
B<1> Z;
}
Makes sense, I suppose, but it's tricky to have something shadowed by something that might be a long way off. Luckily you get an error message so when all other avenues are exhausted you can start searching - after you conclude that Intellisense is lying about the definition of X.
Published at
2024-09-19 19:58:43Event JSON
{
"id": "71a90ed932ccc772ffdd0ddaffb050bda1a91cb12cc8e359c8c19e7c95132a77",
"pubkey": "3422fcbc32f333fb2d3481b2e981258af8a0b571869cbfe93c42962410e232ef",
"created_at": 1726775923,
"kind": 1,
"tags": [
[
"proxy",
"https://mathstodon.xyz/users/dpiponi/statuses/113165986932944044",
"activitypub"
]
],
"content": "Here's C++ playing a nasty trick on me:\n\nclass A\n{\n static constexpr int X = 1;\n};\n\ntemplate\u003cint X\u003e\nclass B : public A\n{\n static_assert(X == 1);\n};\n\nint main()\n{\n B\u003c1\u003e Z;\n}\n\nMakes sense, I suppose, but it's tricky to have something shadowed by something that might be a long way off. Luckily you get an error message so when all other avenues are exhausted you can start searching - after you conclude that Intellisense is lying about the definition of X.",
"sig": "e463fd1b3713f423d2d7a28d88ab2f52439dc3b4b44bfe0c89c7aa22b2dd03cb3846304a1a96b7691a56c278b422868e265ab93539e4ce18a266ff629ba226c1"
}