Skip to content

only use brace initialization for clGetPlatformIDs when anonymous unions are supported #256

@bashbaug

Description

@bashbaug

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
    ,
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions