Skip to content

Do something about the windows compilation warning: C++ designated initializers only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions] #63

Closed

Description

@gregorgorjanc

On https://win-builder.r-project.org we get

* checking whether package 'RcppTskit' can be installed ... WARNING
Found the following significant warnings:
../inst/include/tskit/tskit/core.h:171:21: warning: C++ designated initializers only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]

The code causing this is

/*
We define a specific NAN value for default mutation time which indicates
the time is unknown. We use a specific value so that if mutation time is set to
a NAN from a computation we can reject it. This specific value is a non-signalling
NAN with the last six fraction bytes set to the ascii of "tskit!"
*/
#define TSK_UNKNOWN_TIME_HEX 0x7FF874736B697421ULL
static inline double
__tsk_nan_f(void)
{
    const union {
        uint64_t i;
        double f;
    } nan_union = { .i = TSK_UNKNOWN_TIME_HEX };
    return nan_union.f;
}

The .i = is throwing the error, but only on CRAN Windows (not on GitHub windows or R Universe windows) and chat with tskit-devs suggests this is CRAN windows toolset issue tskit-dev/tskit#3375.

This is currently blocking CRAN submission :( #45

Activity

  1. self-assigned this
    on Feb 8, 2026
  2. gregorgorjanc commented on Feb 9, 2026

    @gregorgorjanc
    MemberAuthor

    I tried submission to https://win-builder.r-project.org with:

    • Removing the above mentioned .i = and the win-builder compiles without a WARNING, however this would require upstream change of valid C code :(

    • Adding CXX_STD = CXX20 to Makevars and the win-builder compiles without a WARNING, so I think I will go with this option at this stage to get over this hurdle and evaluate downstream if this limits distribution of RcppTskit due to specifying C++ 2020 standard (which seems to become broadly used 2021-2023, so some older systems might complain!?)

    • A third alternative, that I did not check, seems to be to ignore warnings from tskit/core.h using the following in our shim core.h - not sure if I like or dislike this option ... but is one option if specifying C++ 2020 standard is too limiting.

    #ifndef RCPPTSKIT_TSKIT_CORE_H
    #define RCPPTSKIT_TSKIT_CORE_H
    
    #if defined(__cplusplus)
      #if defined(__clang__)
        #pragma clang diagnostic push
        #pragma clang diagnostic ignored "-Wc++20-extensions"
      #elif defined(__GNUC__)
        #pragma GCC diagnostic push
        #pragma GCC diagnostic ignored "-Wc++20-extensions"
      #endif
    #endif
    
    #include <tskit/tskit/core.h>
    
    #if defined(__cplusplus)
      #if defined(__clang__)
        #pragma clang diagnostic pop
      #elif defined(__GNUC__)
        #pragma GCC diagnostic pop
      #endif
    #endif
    
    /* existing shim content ... */
    
    #endif```
    
  3. added a commit that references this issue on Feb 9, 2026
    b2e8ae3
  4. gregorgorjanc commented on Feb 9, 2026

    @gregorgorjanc
    MemberAuthor

    Done in #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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