是的,您的观察是正确的。
这可能不是预期的行为,如果您关心此功能,那么我建议向上游报告它。
但请注意,这是有效的:
touch 1.cc
g++ -Wnon-virtual-dtor -Q --help=warning,c++ 1.cc
IE。如果存在具有正确扩展名的输入文件,则会调用正确的编译器正确的可执行文件:cc1plus
, not cc1
。如果不存在输入文件,则后者是默认值。我做了一些快速调试,这是如何发生的:
// gcc.c:
driver::do_spec_on_infiles () const
{
...
for (i = 0; (int) i < n_infiles; i++)
{
...
/* Figure out which compiler from the file's suffix. */
input_file_compiler
= lookup_compiler (infiles[i].name, input_filename_length,
infiles[i].language);
if (input_file_compiler)
{
...
value = do_spec (input_file_compiler->spec);
And input_file_compiler
此时就是 C 编译器,因为
p n_infiles
$9 = 1
(gdb) p infiles[0]
$10 = {name = 0x4cbfb0 "help-dummy", language = 0x4cbfae "c", incompiler = 0x58a920, compiled = false, preprocessed = false}
这是创建虚拟文件的方式(函数process_command
在同一文件中):
if (n_infiles == 0
&& (print_subprocess_help || print_help_list || print_version))
{
/* Create a dummy input file, so that we can pass
the help option on to the various sub-processes. */
add_infile ("help-dummy", "c");
}