"control reaches end of non-void function" 产生错误而不是警告
"control reaches end of non-void function" produces error instead of warning
我正在尝试编译一个大型项目 (https://github.com/ESCOMP/CTSM)。如果可能的话,我想按原样编译它,而不编辑代码(众所周知,它可以在许多平台上成功构建)。
我正在使用 gcc (SUSE Linux) 11.2.1
。我得到
In function ncmp : /run/media/dominic/hdbtrfs/dominic/git/ESCOMP/CTSM/cime/src/share/timing/gptl.c:4069:1: error: control reaches end of non-void function [-Werror=return-type]
来自以下函数。我相信早期版本的 gcc 在这种情况下只会给出警告而不是错误。
/*
** ncmp: compares values of memory adresses pointed to by a pointer. for use with qsort
*/
static int ncmp( const void *pa, const void *pb )
{
static const char *thisfunc = "GPTLsetoption";
const char** x = (const char**)pa;
const char** y = (const char**)pb;
if( *x > *y )
return 1;
if( *x < *y )
return -1;
if( *x == *y )
GPTLerror("%s: shared memory address between timers\n", thisfunc);
}
我希望可以通过在函数末尾插入虚假的 return
语句来解决此问题,但由于我有兴趣尝试构建代码的未修改版本(我目前不是项目的贡献者,所以不能将更改推送到上游)我想知道是否有使用编译器标志将此错误转换为警告的解决方法?
此处要求的是由 makefile 生成的 gcc 调用:
mpicc -c -I/run/media/dominic/hdbtrfs/dominic/git/ESCOMP
/CTSM/cime/src/share/timing -std=gnu99 -O -DCESMCOUPLED
-DFORTRANUNDERSCORE -DNO_R16 -DCPRGNU -DCESMCOUPLED
-DFORTRANUNDERSCORE -DNO_R16 -DCPRGNU -DNUOPC_INTERFACE
-DHAVE_MPI /run/media/dominic/hdbtrfs/dominic/git/ESCOMP
/CTSM/cime/src/share/timing/gptl.c
I'm wondering if there's a workaround to convert this error to a warning using compiler flags?
我希望 -Wno-error
选项具有这种效果。也应该可以将其范围缩小到您报告的特定诊断,但要注意:单独使用 command-line 选项无法将影响缩小到问题的这个特定实例。
附录
问题已被编辑以显示诊断类别是 return-type
,我可以说人们会使用 -Wno-error=return-type
来使所有此类诊断成为警告而不是错误。
-Werror
将所有警告提升为错误。您可以使用 -Wno-error=<i>WarningName</i>
反转此特定警告,例如 -Wno-error=return-type
,如明确记录在 the GCC documentation for warning options:
This switch [-Werror=
] takes a negative form, to be used to negate -Werror
for specific warnings; for example -Wno-error=switch
makes -Wswitch
warnings not be errors, even when -Werror
is in effect.
我正在尝试编译一个大型项目 (https://github.com/ESCOMP/CTSM)。如果可能的话,我想按原样编译它,而不编辑代码(众所周知,它可以在许多平台上成功构建)。
我正在使用 gcc (SUSE Linux) 11.2.1
。我得到
In function ncmp : /run/media/dominic/hdbtrfs/dominic/git/ESCOMP/CTSM/cime/src/share/timing/gptl.c:4069:1: error: control reaches end of non-void function [-Werror=return-type]
来自以下函数。我相信早期版本的 gcc 在这种情况下只会给出警告而不是错误。
/*
** ncmp: compares values of memory adresses pointed to by a pointer. for use with qsort
*/
static int ncmp( const void *pa, const void *pb )
{
static const char *thisfunc = "GPTLsetoption";
const char** x = (const char**)pa;
const char** y = (const char**)pb;
if( *x > *y )
return 1;
if( *x < *y )
return -1;
if( *x == *y )
GPTLerror("%s: shared memory address between timers\n", thisfunc);
}
我希望可以通过在函数末尾插入虚假的 return
语句来解决此问题,但由于我有兴趣尝试构建代码的未修改版本(我目前不是项目的贡献者,所以不能将更改推送到上游)我想知道是否有使用编译器标志将此错误转换为警告的解决方法?
此处要求的是由 makefile 生成的 gcc 调用:
mpicc -c -I/run/media/dominic/hdbtrfs/dominic/git/ESCOMP
/CTSM/cime/src/share/timing -std=gnu99 -O -DCESMCOUPLED
-DFORTRANUNDERSCORE -DNO_R16 -DCPRGNU -DCESMCOUPLED
-DFORTRANUNDERSCORE -DNO_R16 -DCPRGNU -DNUOPC_INTERFACE
-DHAVE_MPI /run/media/dominic/hdbtrfs/dominic/git/ESCOMP
/CTSM/cime/src/share/timing/gptl.c
I'm wondering if there's a workaround to convert this error to a warning using compiler flags?
我希望 -Wno-error
选项具有这种效果。也应该可以将其范围缩小到您报告的特定诊断,但要注意:单独使用 command-line 选项无法将影响缩小到问题的这个特定实例。
附录
问题已被编辑以显示诊断类别是 return-type
,我可以说人们会使用 -Wno-error=return-type
来使所有此类诊断成为警告而不是错误。
-Werror
将所有警告提升为错误。您可以使用 -Wno-error=<i>WarningName</i>
反转此特定警告,例如 -Wno-error=return-type
,如明确记录在 the GCC documentation for warning options:
This switch [
-Werror=
] takes a negative form, to be used to negate-Werror
for specific warnings; for example-Wno-error=switch
makes-Wswitch
warnings not be errors, even when-Werror
is in effect.