Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift cannot import libstdc++-13 chrono header in C++23 mode #76809

Open
ADKaster opened this issue Oct 1, 2024 · 0 comments
Open

Swift cannot import libstdc++-13 chrono header in C++23 mode #76809

ADKaster opened this issue Oct 1, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@ADKaster
Copy link
Contributor

ADKaster commented Oct 1, 2024

Description

Importing STL headers from gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0 as shipped by Ubuntu 24.04 fails to compile due to errors compiling libstdc++ with -std=c++23

This seems to only happen when doing an emit-cxx-headers call from the frontend, and not during emit-executable?

Reproduction

The same test case files as #75593, just using ubuntu 24.04,

And a tweak to include <chrono>

I've created a project here that can reproduce the issue ADKaster/swift-shlib-cxx-exe with

cmake -B build -GNinja && cmake --build build

The necessary change to reproduce this issue, rather than 75593, is to add an include to Color.h

Color.h

#pragma once

// ADD chrono
#include <chrono>

#include <stdint.h>

class Color
{
public:
    Color() = default;
    explicit Color(uint32_t rep) : m_rep(rep) { }

    static bool fromString(Color&, char const*);

private: 
    uint32_t m_rep { 0 };
};

A minimized frontend command is like so:
swiftc -frontend -typecheck -Ishlib shlib/Color.swift -Xcc -std=c++23 -module-name ShlibSwift -cxx-interoperability-mode=default -emit-clang-header-path Color-Swift.h

<unknown>:0: note: in defaulted move constructor for 'std::chrono::time_zone' first required here
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:97:16: error: invalid application of 'sizeof' to an incomplete type 'std::chrono::time_zone::_Impl'
 95 | 	static_assert(!is_void<_Tp>::value,
 96 | 		      "can't delete pointer to incomplete type");
 97 | 	static_assert(sizeof(_Tp)>0,
    |                `- error: invalid application of 'sizeof' to an incomplete type 'std::chrono::time_zone::_Impl'
 98 | 		      "can't delete pointer to incomplete type");
 99 | 	delete __ptr;
    :
402 | 	auto& __ptr = _M_t._M_ptr();
403 | 	if (__ptr != nullptr)
404 | 	  get_deleter()(std::move(__ptr));
    |    `- note: in instantiation of member function 'std::default_delete<std::chrono::time_zone::_Impl>::operator()' requested here
405 | 	__ptr = pointer();
406 |       }

/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/chrono:2639:7: note: in instantiation of member function 'std::unique_ptr<std::chrono::time_zone::_Impl>::~unique_ptr' requested here
2637 |     {
2638 |     public:
2639 |       time_zone(time_zone&&) = default;
    |       `- note: in instantiation of member function 'std::unique_ptr<std::chrono::time_zone::_Impl>::~unique_ptr' requested here
2640 |       time_zone& operator=(time_zone&&) = default;
2641 | 
    :
2710 |       friend class tzdb_list;
2711 | 
2712 |       struct _Impl;
    |              `- note: forward declaration of 'std::chrono::time_zone::_Impl'
2713 | 
2714 |       explicit time_zone(unique_ptr<_Impl> __p);

Expected behavior

A compiling example with -std=c++23, as it works with std=c++20 and below.

Environment

Swift version 6.1-dev (LLVM 89ccf4b8a46135a, Swift 6a5ae8d)
Target: x86_64-unknown-linux-gnu

Additional information

error output from cmake build with chrono added
[1/5] Generating '/home/andrew/ladybird-org/testing/swift-tests/swift-shlib-cxx-exe/build/shlib/include/shlib-Swift.h'
FAILED: shlib/include/shlib-Swift.h /home/andrew/ladybird-org/testing/swift-tests/swift-shlib-cxx-exe/build/shlib/include/shlib-Swift.h 
cd /home/andrew/ladybird-org/testing/swift-tests/swift-shlib-cxx-exe/shlib && /home/andrew/.local/bin/swiftc -frontend -typecheck -I/home/andrew/ladybird-org/testing/swift-tests/swift-shlib-cxx-exe/shlib Color.swift -Xcc -std=c++23 -module-name SwiftShlib -cxx-interoperability-mode=default -emit-clang-header-path /home/andrew/ladybird-org/testing/swift-tests/swift-shlib-cxx-exe/build/shlib/include/shlib-Swift.h
<unknown>:0: note: in defaulted move constructor for 'std::chrono::time_zone' first required here
/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:97:16: error: invalid application of 'sizeof' to an incomplete type 'std::chrono::time_zone::_Impl'
  95 | 	static_assert(!is_void<_Tp>::value,
  96 | 		      "can't delete pointer to incomplete type");
  97 | 	static_assert(sizeof(_Tp)>0,
     |                `- error: invalid application of 'sizeof' to an incomplete type 'std::chrono::time_zone::_Impl'
  98 | 		      "can't delete pointer to incomplete type");
  99 | 	delete __ptr;
     :
 402 | 	auto& __ptr = _M_t._M_ptr();
 403 | 	if (__ptr != nullptr)
 404 | 	  get_deleter()(std::move(__ptr));
     |    `- note: in instantiation of member function 'std::default_delete<std::chrono::time_zone::_Impl>::operator()' requested here
 405 | 	__ptr = pointer();
 406 |       }

/usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/chrono:2639:7: note: in instantiation of member function 'std::unique_ptr<std::chrono::time_zone::_Impl>::~unique_ptr' requested here
2637 |     {
2638 |     public:
2639 |       time_zone(time_zone&&) = default;
     |       `- note: in instantiation of member function 'std::unique_ptr<std::chrono::time_zone::_Impl>::~unique_ptr' requested here
2640 |       time_zone& operator=(time_zone&&) = default;
2641 | 
     :
2710 |       friend class tzdb_list;
2711 | 
2712 |       struct _Impl;
     |              `- note: forward declaration of 'std::chrono::time_zone::_Impl'
2713 | 
2714 |       explicit time_zone(unique_ptr<_Impl> __p);
ninja: build stopped: subcommand failed.
@ADKaster ADKaster added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant