On Wed, 12 Nov 2025 08:36:32 GMT, Kim Barrett <[email protected]> wrote:

>> src/hotspot/share/cppstdlib/new.hpp line 79:
>> 
>>> 77: // Visual Studio => error C2370: '...': redefinition; different storage 
>>> class
>>> 78: #ifndef TARGET_COMPILER_visCPP
>>> 79: [[deprecated]] extern const size_t 
>>> hardware_destructive_interference_size;
>> 
>> At cppreference this is declared as:
>> 
>> inline constexpr size_t hardware_destructive_interference_size
>> 
>> 
>> Is that why you're getting the Visual Studio error?
>
> It can't be redeclared with the `[[deprecated]]` attribute using that form.
> `constexpr` requires an initializer, and what should the value be? And all
> `inline` declarations need to be "exactly the same" (which has a technical
> meaning somewhere that talks about equivalent token sequences).
> 
> Removing `extern`, adding `inline`, or both leads to gcc to (quite correctly,
> I think) rejecting it as a redefinition.
> 
> I think the form being used here does have the same storage class. I think
> both forms declare a variable with namespace scope and external linkage; C++17
> 6.5. And both gcc and clang accept it. I _think_ it's an MSVC bug of being
> overly restrictive, rather than both gcc and clang being overly permissive.

I'm still note convinced that the above does what you intended to do here, but 
the result seems to be the same so I guess that's fine.

If I compile a small test:

#include <stdio.h>

[[deprecated]] inline constexpr int my_deprecated = 1;

int main() {
  printf("my_deprecated: %d\n", my_deprecated);
  return 0;
}

I get:

$ g++ -std=c++17 -Wall -Wextra -pedantic h.cpp
h.cpp:6:33: warning: 'my_deprecated' is deprecated [-Wdeprecated-declarations]
    6 |   printf("my_deprecated: %d\n", my_deprecated);
      |                                 ^
h.cpp:3:3: note: 'my_deprecated' has been explicitly marked deprecated here
    3 | [[deprecated]] inline constexpr int my_deprecated = 1;
      |   ^
1 warning generated.


But if I try to compile something similar to the above code I don't get the 
deprecated warning:

#include <stdio.h>
#include <new>

namespace std {
[[deprecated]] extern const size_t hardware_destructive_interference_size;
};

int main() {
  printf("x = %zu\n", std::hardware_destructive_interference_size);
  return 0;
}

Now I get:

$ g++ -std=c++17 -Wall -Wextra -pedantic g.cpp
g.cpp:9:28: error: reference to 'hardware_destructive_interference_size' is 
ambiguous
    9 |   printf("x = %zu\n", std::hardware_destructive_interference_size);
      |                       ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__new/interference_size.h:25:25:
 note: candidate found by name lookup is 
'std::__1::hardware_destructive_interference_size'
   25 | inline constexpr size_t hardware_destructive_interference_size  = 
__GCC_DESTRUCTIVE_SIZE;
      |                         ^
g.cpp:5:36: note: candidate found by name lookup is 
'std::hardware_destructive_interference_size'
    5 | [[deprecated]] extern const size_t 
hardware_destructive_interference_size;
      |                                    ^
1 error generated.

where the end result is that we get a warning about an ambiguous lookup and not 
a warning that this has been deprecated.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28250#discussion_r2518263890

Reply via email to