Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST]: Add auto replacement C++ compiler options to alternative between GCC, Clang and MSVC #6196

Closed
raidenluikang opened this issue Feb 26, 2024 · 6 comments
Labels
request Request for something

Comments

@raidenluikang
Copy link

Is your feature request related to a problem? Please describe

When change gcc compiler to MSVC compiler gcc specific compiler options required manually change.
For example -O2 -Wall -std=c++20
However, these options has alternatives in MSVC. So why don't automatic replacement they?

Describe the solution you'd like

If from GCC or Clang compiler change to MSVC in compiler editor automatic replace compiler options to its alternative in MSVC compiler, for example: replace -O2 to /O2, -Wall to /Wall , -std=c++20 to /std:c++20

And vice-versa, when change compiler from MSVC to GCC or Clang automatic replace compiler options back.

Describe alternatives you've considered

There also a strange situation, when change Clang compiler to GCC,

-stdlib=libc++ 

option should be removed, or discarded in GCC compiler.
Always manually fix compiler options are tedious !

If some compiler specific compiler options can't have alternative -- may be they , simple need to deleted from options editor?

Additional context

Not applicable

@raidenluikang raidenluikang added the request Request for something label Feb 26, 2024
@dkm
Copy link
Member

dkm commented Feb 26, 2024

Hello,

This looks very complex to solve in the general case. We won't be able to come up with a 1:1 mapping for all options/compilers combinations. The closer we would be able to do is some find/replace for known options, but that would end up doing some pretty strange result for populated command lines... We would change some options only and get something like -Wsomething-we-dont-change /O3 /Wall -flto -fuse-ld=mold.

I don't see a good way of implementing this feature. Maybe you have better suggestion?

@cpplearner
Copy link

cpplearner commented Feb 26, 2024

It's unclear whether -Wall should be mapped to /Wall. MSVC's /Wall is more like Clang's -Weverything.

MSVC's /std: accepts different values from GCC's -std=. For example, the former does not accept c++11 or gnu++14. Also, the meaning of /std:c++latest changes over time. It could mean C++20 or C++23, depending on the compiler version.

@raidenluikang
Copy link
Author

raidenluikang commented Feb 27, 2024

I understand, but could you mapped -std=c++<N> <--> /std:c++<N> and -O<M> <--> /O<M>, also -Wall <--> /W4 when changed GCC to MSVC or Clang to MSVC, or vice versa ?

I thought, GCC 's -Wall should be mapped to MSVC's /W4 .

Latest, but optional feature:
MSVC /std:c++latest --> need to convert correct /std:c++<N> appropriate MSVC compiler version,
and after that map to -std=c++<N> ?

All other options remains without change, or removed --> It's up to you

@raidenluikang
Copy link
Author

Also MSVC has strange behavior, even has /std:c++20 or /std:c++17 option , __cplusplus macros don't changed.

Could you append /Zc:__cplusplus compiler option when -std=c++<N> converted to /std:c++<N> ?

@OfekShilon
Copy link
Member

Some easy examples:

  • clang/gcc have -fno-semantic-interposition which can't be mapped to msvc - interposition is a linux-only property.
  • clang/gcc have -gdwarf-5 which can't be mapped to msvc, as it generates pdb debug-info files and not dwarf.
  • gcc/clang have a few hundreds optimization flags, msvc essentially has /O0, /O1 and /O2 (and a handful of others). Clearly no mapping is possible.

etc. etc. etc. For the huge majority of switches such a translation inherently isn't possible, and I believe trying to do this for the small subset of switches where it is - would add confusion instead of decreasing it.

@OfekShilon OfekShilon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 23, 2024
@rmccampbell
Copy link

I think a better solution to this is #2214, which was suggested almost 4 years ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Request for something
Projects
None yet
Development

No branches or pull requests

5 participants