On Wed, 12 Nov 2025 07:38:53 GMT, Stefan Karlsson <[email protected]> wrote:

>> 8369187: Add wrapper for <new> that forbids use of global allocation and 
>> deallocation functions
>> 
>> Please review this change that adds `cppstdlib/new.hpp` as a wrapper for
>> including `<new>`. All existing inclusions of `<new>` are changed to include
>> the new wrapper.
>> 
>> In additional to including `<new>`, this wrapper also provides deprecation
>> declarations to prevent the use of some facilities by HotSpot code.
>> 
>> However, those deprecations need to be conditionalized to not apply to 
>> gtests,
>> so this change also adds a macro definition provided by the build system for
>> use in detecting that a header is being included by a gtest.
>> 
>> Testing: mach5 tier1
>
> 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.

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

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

Reply via email to