argparse icon indicating copy to clipboard operation
argparse copied to clipboard

warning C5246 - double curly braces

Open BeErikk opened this issue 10 months ago • 1 comments

Just FYI, using MSVCtools 14.42.34433, compiler 19.42.34438 (Visual Studio 2022) with -Wall, compiles gives:

argparse.hpp(1703): warning C5246: '_Elems': the initialization of a subobject should be wrapped in braces argparse.hpp(1703): note: the template instantiation context (the oldest one first) is argparse.hpp(1647): note: see reference to function template instantiation 'argparse::Argument &argparse::ArgumentParser::add_argument<const char*,const char*>(const char *,const char *)' being compiled

See for example discussion at stackoverflow double curly braces.

It's not an error but a simple solution is for example something like

#if defined(_MSC_VER)
#define MSDISABLE_WARNING_PUSH(x)	__pragma(warning(push));__pragma(warning(disable:x))
#define MSDISABLE_WARNING_POP		__pragma(warning(pop))
#else
#define MSDISABLE_WARNING_PUSH(x)
#define MSDISABLE_WARNING_POP
#endif

MSDISABLE_WARNING_PUSH(5246)
code ...
MSDISABLE_WARNING_POP

ugly though

BeErikk avatar Feb 20 '25 21:02 BeErikk

Another solution is to add curly braces as follows:

argparse-diff.txt

BeErikk avatar Feb 21 '25 08:02 BeErikk