We hit a problem recently in the OpenCL-CLHPP CI where OpenCL ICD loader builds with CMAKE_C_EXTENSIONS=OFF produced anonymous union / brace initialization warnings. Because the CI builds with warnings-as-errors, this caused CI to fail.
KhronosGroup/OpenCL-CLHPP#330
/home/bashbaug/git/OpenCL-ICD-Loader/loader/icd_dispatch_generated.c:6828:5: warning: braces around scalar initializer
6828 | {&clGetPlatformIDs_disp},
At least on my system, the difference between CMAKE_C_EXTENSIONS=OFF and the default CMAKE_C_EXTENSIONS=ON is that compilation with extensions off passes -std=c99, whereas compilation with extensions on is done with -std=gnu99.
If we want to build with extensions off and hence with -std=c99 we should only use brace initialization when anonymous unions are supported. This may be as simple as something like:
struct _cl_icd_dispatch khrMasterDispatch = {
+#if __CL_HAS_ANON_STRUCT__
{
+#endif
&clGetPlatformIDs_disp
+#if __CL_HAS_ANON_STRUCT__
}
+#endif
,
...
We hit a problem recently in the OpenCL-CLHPP CI where OpenCL ICD loader builds with
CMAKE_C_EXTENSIONS=OFFproduced anonymous union / brace initialization warnings. Because the CI builds with warnings-as-errors, this caused CI to fail.KhronosGroup/OpenCL-CLHPP#330
At least on my system, the difference between
CMAKE_C_EXTENSIONS=OFFand the defaultCMAKE_C_EXTENSIONS=ONis that compilation with extensions off passes-std=c99, whereas compilation with extensions on is done with-std=gnu99.If we want to build with extensions off and hence with
-std=c99we should only use brace initialization when anonymous unions are supported. This may be as simple as something like:struct _cl_icd_dispatch khrMasterDispatch = { +#if __CL_HAS_ANON_STRUCT__ { +#endif &clGetPlatformIDs_disp +#if __CL_HAS_ANON_STRUCT__ } +#endif , ...