Skip to content

Should STL errors use pragma message in order to make the output prettier/more obvious? #2896

@strega-nil-ms

Description

@strega-nil-ms

Currently, our STL errors look like:

#error STL1003: Unexpected compiler, expected C++ compiler.

This results in the following output from MSVC:

C:\Users\nimazzuc\projects\stl\out\x64\out/inc\yvals_core.h(687): fatal error C1189: #error STL1003: Unexpected compiler, expected C++ compiler.

This is as opposed to our STL warnings, which result in much prettier output:

C:\Users\nimazzuc\projects\stl\out\x64\out/inc\yvals.h(238): warning STL4000: _STATIC_CPPLIB is deprecated and will be REMOVED.

Do we wish to use pragma message instead, so that we get prettier output?

Something like:

// yvals_core.h
// preprocessor fun
#define _STL_PRAGMA(PRAGMA) _Pragma(#PRAGMA)
#define _STL_PRAGMA_MESSAGE(MESSAGE) _STL_PRAGMA(message(MESSAGE))

// note: clang-format does weird things to this
// clang-format off
#define _ERROR_MESSAGE(NUMBER, MESSAGE) \
    _STL_PRAGMA_MESSAGE(__FILE__ "(" _CRT_STRINGIZE(__LINE__) "): error STL" #NUMBER ": " MESSAGE) \
    static_assert(false, "Error in C++ Standard Library usage.")
// clang-format on

called like:

#ifndef __cplusplus
_ERROR_MESSAGE(1003, "Unexpected compiler, expected C++ compiler.");
#endif

resulting in the following output:

PS C:\..\nimazzuc\projects\stl-tests> cl /c test.cxx
Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31517 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cxx
test.cxx(12): error STL1004: Unexpected compiler, expected C++ compiler.
test.cxx(12): error C2338: static_assert failed: 'Error in C++ Standard Library usage.'

which I at least believe is far more readable (and is probably better for VS diagnostics as well)

(if we do make this change, we should do the same pragma preprocessor nonsense for _WARNING_MESSAGE

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improvedfixedSomething works now, yay!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions