Skip to content

Address of dllimport symbol is not constexpr #50900

@skyostil

Description

@skyostil
mannequin
Bugzilla Link 51558
Version trunk
OS Windows NT
CC @DougGregor,@zmodem,@zygoloid,@rnk

Extended Description

The following C++ program fails to compile on the x64_64-pc-windows-msvc target:

  extern __declspec(dllimport) int x;
  constexpr int* y = &x;

Error message:

  test.cc(7,16): error: constexpr variable 'y' must be initialized by a constant expression

This is on Clang version 14.0.0 (https://github.com/llvm/llvm-project/ee65938357d5fffe9e586fa155b37268b5a358ac), target: x86_64-pc-windows-msvc. I ran into this while trying to compile Perfetto (https://perfetto.dev) as a part of Chromium.

The same program builds correctly on MSVC (tested on 19.29.30037 for x64). Interestingly, MSVC had a regression related to this in 2018[1] which has since been fixed.

[1] https://developercommunity.visualstudio.com/t/c-regression-stdmax-of-two-constexpr-does-not-eval/312456

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationextension:microsoft

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions