Skip to content

error: non-type template argument is not a constant expression with 32-bit address space #82490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ararmine opened this issue Feb 21, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" constexpr Anything related to constant evaluation

Comments

@ararmine
Copy link

ararmine commented Feb 21, 2024

The following C++ code is not compiled with clang x86-64 v17.0.1 with MS extensions enabled, while it compiles successfully with X86 msvc v19.
Steps to reproduce:

  1. cat test.cpp
typedef void                OpcUa_Void;

typedef OpcUa_Void (*__ptr32 PfnClear)(OpcUa_Void* __ptr32);

template<class T, PfnClear fctClear>
class UaStackTypeArray
{};

OpcUa_Void ClearNothing(void* __ptr32);

template class UaStackTypeArray<bool, ClearNothing>;
  1. clang test.cpp -S -fms-extensions
test.cpp:12:39: error: non-type template argument is not a constant expression
   12 | template class UaStackTypeArray<bool, ClearNothing>;
      |                                       ^~~~~~~~~~~~
test.cpp:12:39: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
1 error generated.
@tbaederr tbaederr added clang:frontend Language frontend issues, e.g. anything involving "Sema" constexpr Anything related to constant evaluation and removed new issue labels Feb 21, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (ararmine)

The following C++ code is not compiled with clang x86-64 v17.0.1 with MS extensions enabled, while it compiles successfully with X86 msvc v19. Steps to reproduce:
  1. cat test.cpp
typedef void                OpcUa_Void;

typedef OpcUa_Void (*__ptr32 PfnClear)(OpcUa_Void* __ptr32);

template&lt;class T, PfnClear fctClear&gt;
class UaStackTypeArray
{};

OpcUa_Void ClearNothing(void* __ptr32);

template class UaStackTypeArray&lt;bool, ClearNothing&gt;;
  1. clang test.cpp -S -fms-extensions
test.cpp:12:39: error: non-type template argument is not a constant expression
   12 | template class UaStackTypeArray&lt;bool, ClearNothing&gt;;
      |                                       ^~~~~~~~~~~~
test.cpp:12:39: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
1 error generated.

@shafik
Copy link
Collaborator

shafik commented Feb 21, 2024

This looks very similar to #12488 which was closed as won't fix.

CC @AaronBallman for second set of 👀

@zygoloid
Copy link
Collaborator

I think this is different -- this isn't an arbitrary reinterpret_cast conversion, it's just a CK_AddressSpaceConversion, which we could in principle permit in constant evaluation (perhaps just in this case, or perhaps in general). It'd be a bit of work to do, including IR generation changes, but probably not too hard.

I think the bigger problem is that the backend doesn't support these constants either: https://godbolt.org/z/4GW9cbenr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" constexpr Anything related to constant evaluation
Projects
None yet
Development

No branches or pull requests

5 participants