Skip to content

Do not use compound literals (fix MSVC C4576) - #14276

Merged
alalek merged 3 commits into
opencv:3.4from
kiwixz:pr/fix_compound
Apr 11, 2019
Merged

alalek merged 3 commits into
opencv:3.4from
kiwixz:pr/fix_compound

Conversation

@kiwixz

@kiwixz kiwixz commented Apr 8, 2019 •

Copy link
Copy Markdown
Contributor

They are not part of the C++ standard, and MSVC will error out:

error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax

See godbolt example.

@alalek

alalek commented Apr 8, 2019 •

Copy link
Copy Markdown
Member

Thank you for the fix of MSVC compilation mode.

Such fixes should go into 3.4 branch first.

Please remove URL from commit description (it will be linked to this PR anyway).

BTW,

  • GCC without C++11 doesn't like this (check your godbolt example with GCC 4.8.5 or 5.4)

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11

  • clang 4 - 2 errors.

So we need more compatible solution for that.


https://en.cppreference.com/w/c/language/compound_literal

@kiwixz
kiwixz changed the base branch from master to 3.4 April 8, 2019 13:42
@alalek

alalek commented Apr 8, 2019

Copy link
Copy Markdown
Member

@kiwixz Could you provide some details how to reproduce problem with MSVC? Do you compile for ARM64 target? PowerPC?

@kiwixz

kiwixz commented Apr 8, 2019

Copy link
Copy Markdown
Contributor Author

@alalek Sure, I was just compiling for x86_64 Windows 10. It failed when I tried to build ffmpeg's wrapper. I took the opportunity to grep the codebase and fix other similar constructs.

@alalek

alalek commented Apr 8, 2019

Copy link
Copy Markdown
Member

OK.

Lets provide fix for FFmpeg wrapper only:

#if defined(_MSC_VER) && defined(__cplusplus)
... use initializer list ...
#else 
... current code with compound literal ...
#endif 

Other code should not be processed by MSVC compiler at this moment.

@kiwixz

kiwixz commented Apr 8, 2019

Copy link
Copy Markdown
Contributor Author

@alalek Yep it was a bad idea, sorry. I changed target to 3.4 and fixed it.

@alalek
alalek merged commit c8056b3 into opencv:3.4 Apr 11, 2019
@alalek alalek mentioned this pull request Apr 13, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Do not use compound literals (fix MSVC C4576) (opencv#14276)

* do not use compound literals (compat cpp98)

* only fix msvc path

* remove unnecessary cplusplus check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants