Skip to content

[clang] fails to compile print("{}", 5s) when using libstdc++ #139067

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

Open
Taw3e8 opened this issue May 8, 2025 · 12 comments · May be fixed by #139560
Open

[clang] fails to compile print("{}", 5s) when using libstdc++ #139067

Taw3e8 opened this issue May 8, 2025 · 12 comments · May be fixed by #139560
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue libstdc++ GNU libstdc++ C++ standard library regression

Comments

@Taw3e8
Copy link

Taw3e8 commented May 8, 2025

This fails to compile without adding libc++:

#include <chrono>
#include <print>

int main() {
	using namespace std::chrono_literals;
	std::print("{}", 5s);
}
@llvmbot llvmbot added clang Clang issues not falling into any other category libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. labels May 8, 2025
@frederick-vs-ja frederick-vs-ja changed the title [clang] fails to compile print("{}", 5s) without libc++ [clang] fails to compile print("{}", 5s) when using libstdc++ May 8, 2025
@frederick-vs-ja frederick-vs-ja added libstdc++ GNU libstdc++ C++ standard library and removed libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. labels May 8, 2025
@frederick-vs-ja
Copy link
Contributor

Reduced example (Godbolt link):

template <class R>
constexpr auto kind =
  primary_template_not_defined(
    kind<R> // How can this hack be valid!
  );

template <class T, decltype(sizeof(0)) N>
constexpr int kind<T[N]> = 0;

This was accepted by old versions of Clang, but not the trunk...

@frederick-vs-ja frederick-vs-ja added clang:frontend Language frontend issues, e.g. anything involving "Sema" regression diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue diverges-from:edg Does the clang frontend diverge from edg compiler and removed clang Clang issues not falling into any other category labels May 8, 2025
@llvmbot
Copy link
Member

llvmbot commented May 8, 2025

@llvm/issue-subscribers-clang-frontend

Author: Jan Piotrowicz (Taw3e8)

This [fails to compile](https://godbolt.org/z/EWrMKdd3o) without adding libc++:
#include &lt;chrono&gt;
#include &lt;print&gt;

int main() {
	using namespace std::chrono_literals;
	std::print("{}", 5s);
}

@erichkeane
Copy link
Collaborator

erichkeane commented May 8, 2025

Reduced example (Godbolt link):

template <class R>
constexpr auto kind =
  primary_template_not_defined(
    kind<R> // How can this hack be valid!
  );

template <class T, decltype(sizeof(0)) N>
constexpr int kind<T[N]> = 0;

This was accepted by old versions of Clang, but not the trunk...

Looks like this example fails in GCC as well if you instantiate kind for the same reason. So assuming this is accurate, this is a case of Clang diagnosing a 'never valid' template immediately, which I believe is correct behavior.

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented May 8, 2025

Looks like this example fails in GCC as well if you instantiate kind for the same reason. So assuming this is accurate, this is a case of Clang diagnosing a 'never valid' template immediately, which I believe is correct behavior.

Hmm, the primary template is assumed to be never valid, which is required for std::format_kind ([format.range.fmtkind]/1).

Although libstdc++'s technique looks too tricky for me...

@frederick-vs-ja
Copy link
Contributor

This seems to be caused by #134522. CC @zwuis.

@cor3ntin
Copy link
Contributor

cor3ntin commented May 9, 2025

@jwakely fyi

@jwakely
Copy link
Contributor

jwakely commented May 9, 2025

@cor3ntin
Copy link
Contributor

Should we revert #134522 until libstdc++ is fixed? This seems rather disruptive at the moment @zwuis @AaronBallman @erichkeane

@zwuis
Copy link
Contributor

zwuis commented May 11, 2025

Should we revert #134522 until libstdc++ is fixed? This seems rather disruptive at the moment @zwuis @AaronBallman @erichkeane

I have no idea. It depends on you.

@AaronBallman
Copy link
Collaborator

Should we revert #134522 until libstdc++ is fixed? This seems rather disruptive at the moment @zwuis @AaronBallman @erichkeane

I think that's a sufficiently new change to be worth reverting until we can find a way to work around the issue (even if it's a compatibility hack that only works in system headers).

@erichkeane
Copy link
Collaborator

Should we revert #134522 until libstdc++ is fixed? This seems rather disruptive at the moment @zwuis @AaronBallman @erichkeane

I think that's a sufficiently new change to be worth reverting until we can find a way to work around the issue (even if it's a compatibility hack that only works in system headers).

Its a little more than a month old and fixes some pretty annoying bugs. I'd like for us to not revert this if possible. Is @zwuis around? I would really like it if we could just put some sort of compatibility hack in place instead.

@frederick-vs-ja
Copy link
Contributor

Should we revert #134522 until libstdc++ is fixed? This seems rather disruptive at the moment @zwuis @AaronBallman @erichkeane

IIUC it's sufficient to just give up early diagnostics for primary templates at this moment. I want a partial revert like that in #139490.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue libstdc++ GNU libstdc++ C++ standard library regression
Projects
None yet
8 participants