Skip to content

Commit 2f734c4

Browse files
committed
goto-gcc: select default language standard depending on emulated compiler
This ensures that goto-cc with no `-std` explicitly specified will expect the same language standard as the underlying compiler's preprocessor -- so for example, using `goto-cc test.cpp`, which invokes `g++-7 -E` to perform preprocessing, will be able to parse the C++14 constructs in the standard library exposed because g++-6 and above enable C++14 support by default.
1 parent 8cc1848 commit 2f734c4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/goto-cc/gcc_mode.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,69 @@ int gcc_modet::doit()
597597
if(std_string=="gnu++14" || std_string=="c++14")
598598
config.cpp.set_cpp14();
599599
}
600+
else
601+
{
602+
// Set default dialect dependent on what compiler we're emulating:
603+
switch(gcc_version.flavor)
604+
{
605+
case gcc_versiont::flavort::UNKNOWN:
606+
// Leave configt's default in place
607+
break;
608+
609+
case gcc_versiont::flavort::CLANG:
610+
if(gcc_version.v_major >= 6)
611+
{
612+
// NOLINTNEXTLINE(whitespace/line_length)
613+
// https://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html#c-language-changes-in-clang
614+
config.cpp.set_cpp14();
615+
}
616+
else
617+
{
618+
config.cpp.set_cpp98();
619+
}
620+
621+
if(gcc_version.v_major >= 3 && gcc_version.v_minor >= 6)
622+
{
623+
// NOLINTNEXTLINE(whitespace/line_length)
624+
// http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#c-language-changes-in-clang
625+
config.ansi_c.set_c11();
626+
}
627+
else
628+
{
629+
config.ansi_c.set_c99();
630+
}
631+
632+
break;
633+
634+
case gcc_versiont::flavort::GCC:
635+
if(gcc_version.v_major >= 6)
636+
{
637+
// https://gcc.gnu.org/gcc-6/changes.html
638+
config.cpp.set_cpp14();
639+
}
640+
else
641+
{
642+
config.cpp.set_cpp98();
643+
}
644+
645+
if(gcc_version.v_major >= 5)
646+
{
647+
// https://gcc.gnu.org/gcc-5/changes.html
648+
config.ansi_c.set_c11();
649+
}
650+
else
651+
{
652+
config.ansi_c.set_c89();
653+
}
654+
655+
break;
656+
657+
case gcc_versiont::flavort::BCC:
658+
config.ansi_c.set_c89();
659+
660+
break;
661+
}
662+
}
600663

601664
// gcc's default is 32 bits for wchar_t
602665
if(cmdline.isset("short-wchar"))

0 commit comments

Comments
 (0)