-
Notifications
You must be signed in to change notification settings - Fork 153
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
weird 'missing_key' bug since v4.0.3+ #1638
Comments
What compiler are you using? And, if you remove the anonymous namespace ( |
This issue was found on GCC 14.2.0, but it works fine with GCC 13.3.0. The OS in use is Ubuntu 24.04.2 LTS. Regarding the namespace issue, removing the anonymous namespace in either src/unused.cpp or src/main.cpp resolves the issue, but removing it from both files does not. |
After further checking the output of each object file, I found they contain a conflicting symbol. Running nm unused.cpp.o | grep ZN3glz10comparitorIL shows:
And running nm main.cpp.o | grep ZN3glz10comparitorIL shows the exact same symbol. The demangled name of the conflicting symbol is: bool glz::comparitor<glz::decode_index<
glz::opts{10u, true, false, false, true, true, false, false, (char)32, (unsigned char)3, true, false, true},
(anonymous namespace)::tmp_struct,
0ul,
(anonymous namespace)::tmp_struct&,
unsigned long&,
glz::context&,
char const*&,
char const*&
>((anonymous namespace)::tmp_struct&, glz::context&, char const*&, char const*&, unsigned long&)::KeyWithEndQuote, 8ul, char>(char const*) What I don’t understand is why this symbol is marked as globally visible with a weak ( |
It seems using const std::string_view& as template argument result in some unexpected behavior, as in below minimal project. src/a.hpp: #pragma once
#include <string_view>
template <const std::string_view& Str>
auto get_length() {
return Str.length();
} src/main.cpp: #include <iostream>
#include "a.hpp"
namespace {
static constexpr std::string_view sssss = "123";
}
int main() {
std::cout << get_length<sssss>() << std::endl;
return 0;
} src/unused.cpp: #include <string_view>
#include "a.hpp"
namespace {
static constexpr std::string_view sssss = "12345";
auto unused_function() {
return get_length<sssss>();
}
} CMakeLists.txt: cmake_minimum_required(VERSION 3.30)
project(linkage_test)
set(CMAKE_CXX_STANDARD 23)
add_executable(linkage_test src/unused.cpp src/main.cpp) Surprisingly, this program outputs 5, not 3. The issue arises because unused.cpp.o and main.cpp.o contain conflicting definitions of auto get_length<(anonymous namespace)::sssss>(), as shown by running nm: nm unused.cpp.o main.cpp.o | grep _Z10get_lengthIL_ZN12_GLOBAL__N_1L5sssssEEEDav The function is emitted as a W, meaning the linker arbitrarily picks one definition, which results in unexpected behavior. |
Wow, thanks for diving into this issue! This is very interesting. The template instantiation should be based on the reference of the |
Since Glaze version 4.0.3, the following minimal reproducible example produces an unexpected missing_key runtime error when parsing JSON.
This bug seems unusual because making seemingly unrelated modifications (e.g., small changes to the project structure) can prevent reproducing the issue.
src/main.cpp:
src/unused.cpp:
CMakeLists.txt:
This issue appears in v4.0.3 and later, including v5.0.0, but does not occur in earlier versions.
The text was updated successfully, but these errors were encountered: