https://github.com/zmodem commented:

Trying to wrap my head around this. Part of the weirdness comes from having an 
initializer for a dllimport variable in the first place.

We would typically not allow:

```
__declspec(dllimport) int x = 42;
```

`(error: definition of dllimport data)`

But we allow it when the dllimport is inherited via the function for a static 
local, because otherwise a lot of code would break:

```
__declspec(dllimport) constexpr const int* f() {
  static constexpr int x = 42;
  return &x;
}
```

We already seem okay evaluating the address as a constant expression:

```
__declspec(dllimport) constexpr const int* f() {
  static constexpr int x = 42;
  return &x;
} 
static_assert(*f() == 42);
```

But not like this:

```
__declspec(dllimport) constexpr const int* f() {
  static constexpr int x = 42;
  static constexpr const int *p = &x;
  return p;
} 
static_assert(*f() == 42);
```

Even though it's really the same thing? I'm not sure why those two are 
different (that would be interesting to know!).

Maybe this is a simpler test case to work with?

---

In the updated comment, you add "For the [static local] case, we'd still need 
to evaluate the constant expression in case we're inside a (inlined) function."

But isn't there a risk that the expression can leak outside the function, and 
we way try to use it in some constexpr context where it doesn't actually work?

https://github.com/llvm/llvm-project/pull/171628
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to