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

using example from README does not work with gtest and clang++17 #926

Closed
maldag opened this issue Apr 17, 2024 · 7 comments
Closed

using example from README does not work with gtest and clang++17 #926

maldag opened this issue Apr 17, 2024 · 7 comments

Comments

@maldag
Copy link

maldag commented Apr 17, 2024

I'm trying to integrate the glaze library into the project using CMake.
Upon writing an unit testcase with GTest and clang++17 using -std=c++20, I'm facing the following error:

/project/build_gtest/_deps/glaze-src/include/glaze/util/parse.hpp:165:31: error: call to consteval function 'glz::detail::repeat_byte' is not a constant expression [clang-diagnostic-error]
      return has_zero(chunk ^ repeat_byte(Char));
                              ^
/project/build_gtest/_deps/glaze-src/include/glaze/util/parse.hpp:165:43: note: subexpression not valid in a constant expression
      return has_zero(chunk ^ repeat_byte(Char));

The testcode is:

#include <gtest/gtest.h>
#include <string>

#include "glaze/glaze.hpp"

struct my_struct
{
  int i = 287;
  double d = 3.14;
  std::string hello = "Hello World";
  std::array<uint64_t, 3> arr = { 1, 2, 3 };
  std::map<std::string, int> map{{"one", 1}, {"two", 2}};
};


TEST(glaze_test,test1){
    my_struct s{};
    std::string buffer = glz::write_json(s); 
    EXPECT_STREQ(buffer,R"({
        "i": 287,
        "d": 3.14,
        "hello": "Hello World",
        "arr": [
            1,
            2,
            3
        ],
        "map": {
            "one": 1,
            "two": 2
        }
        })"
    );
}

Am I missing something here?

@stephenberry
Copy link
Owner

That is very strange. Looks like a bug in Clang 17, unless something else weird is going on with your setup.

I'll build with Clang 17 and get back to you soon.

@stephenberry
Copy link
Owner

I just built using Clang 17. Can you try building in another environment?

@maldag
Copy link
Author

maldag commented Apr 17, 2024

Which compiler arguments did you add to clang++-17? I used -std=c++20

@stephenberry
Copy link
Owner

-std=c++20 or -std=c++23 should both work

@stephenberry
Copy link
Owner

@maldag, here is an example of it building in compiler explorer with clang17: https://gcc.godbolt.org/z/zon9Mjjh9

@maldag
Copy link
Author

maldag commented Apr 18, 2024

I double checked my environment. Sorry for the noise, I was using and older version of clang-tidy in the buildprocess which caused the failing.

@maldag maldag closed this as completed Apr 18, 2024
@stephenberry
Copy link
Owner

No problem, thanks for explaining the issue.

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

No branches or pull requests

2 participants