Skip to content

Conversation

@yaito3014
Copy link
Owner

attempt to make colorizer constexpr and transform string in constexpr via fixed_string

@yaito3014
Copy link
Owner Author

clang でのみ通る。要調査

@saki7
Copy link
Collaborator

saki7 commented May 20, 2025

たのしそう

@yaito3014
Copy link
Owner Author

yaito3014 commented May 20, 2025

GCC は string_view::find で落ちているが以下のようなミニマルなコードは落ちない
何が起こっているんだ

#include <algorithm>
#include <array>
#include <string_view>

#include <cstddef>

template <std::size_t N>
struct fixed_string {
  std::array<char, N + 1> data{};

  constexpr fixed_string() noexcept = default;
  constexpr fixed_string(const char (&str)[N + 1]) noexcept { std::ranges::copy(str, data.begin()); }

  constexpr std::string_view get() const noexcept { return {data.begin(), N}; }
};

template <std::size_t N>
fixed_string(const char (&)[N]) -> fixed_string<N - 1>;

template <fixed_string S>
struct static_string {
  static constexpr auto len = S.get().find(',');
};

inline constexpr auto x [[maybe_unused]] = static_string<"foo,bar">::len;

int main() {}

@yaito3014
Copy link
Owner Author

ミニマルなコードを書くたびに頭を抱える
https://godbolt.org/z/9osbYdsr4

@saki7
Copy link
Collaborator

saki7 commented May 21, 2025

たのしそう

@cppwarningnotifier

This comment has been minimized.

@cppwarningnotifier

This comment has been minimized.

@cppwarningnotifier

This comment has been minimized.

@saki7

This comment was marked as resolved.

@yaito3014 yaito3014 force-pushed the constexpr-colorize branch from 17bf951 to b4472e6 Compare May 22, 2025 10:43
@cppwarningnotifier

This comment has been minimized.

@cppwarningnotifier

This comment has been minimized.

@cppwarningnotifier

This comment has been minimized.

@cppwarningnotifier

This comment has been minimized.

@cppwarningnotifier
Copy link

Environment C++23 C++26
ubuntu24.04Clang19Debug✅success✅success
Release✅success✅success
20Debug✅success✅success
Release✅success✅success
GCC14Debug✅success✅success
Release✅success✅success
windows2022MSVCv142Debug✅success✅success
Release✅success✅success

@yaito3014 yaito3014 merged commit 6290ed8 into main Jun 19, 2025
18 checks passed
@yaito3014 yaito3014 deleted the constexpr-colorize branch June 19, 2025 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants