Skip to content

_NODISCARD should appear before __declspec #1702

@StephanTLavavej

Description

@StephanTLavavej

@JonCavesMSFT reported:

My recent PR to add a warning for uses of [[nodiscard]] that are ignored, C5240, has shown up an issue with the self-build:

The header file <memory_resource> contains the following line:

extern "C" _CRT_SATELLITE_1 _NODISCARD memory_resource* __cdecl null_memory_resource() noexcept;

Which causes the compiler to emit the new warning: and if you currently call the function as follows:

void f()
{
    null_memory_resource();
}

Then no warning about discarding the return value is emitted.

If I change the declaration of null_memory_resource to:

extern "C" _NODISCARD _CRT_SATELLITE_1 memory_resource* __cdecl null_memory_resource_2() noexcept;

Then the new warning is not emitted and the call to the function does emit, "C4834: discarding return value of function with 'nodiscard' attribute".

To unblock the self-build I will, for now, make this warning off-by-default.

_CRT_SATELLITE_1 is defined to be __declspec(dllexport) or nothing in crtdefs.h; the issue is with an attribute like [[nodiscard]] occuring after a __declspec.

I observe that this also affects a lot of Special Math machinery.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions