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

clang 3.8.0 croaks while trying to compile with debug symbols #1097

Closed
TurpentineDistillery opened this issue May 17, 2018 · 6 comments
Closed

Comments

@TurpentineDistillery
Copy link

To clarify: the compiler aborts, rather than a mere compilation error.
Initial problematic commit: 8e681d1

To reproduce:

//main.cpp
#include "nlohmann/json.hpp"
#include <iostream>
int main()
{
    nlohmann::json j; 
    std::cin >> j; 
    return 0; 
}
>>clang++ -std=c++11  -g main.cpp
clang: /usr/local/llvm/3.8.0/src/llvm-3.8.0.src/lib/IR/Metadata.cpp:192: void llvm::ReplaceableMetadataImpl::replaceAllUsesWith(llvm::Metadata*): Assertion `!(MD && isa<MDNode>(MD) && cast<MDNode>(MD)->isTemporary()) && "Expected non-temp node"' failed.
...
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.8.0 (tags/RELEASE_380/final)
...

Proposed workaround:

  1. Move parse_event_t outside of parser into detail
  2. Remove using parse_event_t = typename parser::parse_event_t; in basic_json
  3. Replace using parser_callback_t = typename parser::parser_callback_t; with using parser_callback_t = std::function<bool(int depth, detail::parse_event_t event, basic_json& parsed)>;
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 8c9942b..d7f133d 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -3321,6 +3321,24 @@ namespace nlohmann
 {
 namespace detail
 {
+
+enum class parse_event_t : uint8_t
+{
+    /// the parser read `{` and started to process a JSON object
+    object_start,
+    /// the parser read `}` and finished processing a JSON object
+    object_end,
+    /// the parser read `[` and started to process a JSON array
+    array_start,
+    /// the parser read `]` and finished processing a JSON array
+    array_end,
+    /// the parser read a key of a value in an object
+    key,
+    /// the parser finished reading a JSON value
+    value
+};
+
+    
 ////////////
 // parser //
 ////////////
@@ -3341,21 +3359,6 @@ class parser
     using token_type = typename lexer_t::token_type;
 
   public:
-    enum class parse_event_t : uint8_t
-    {
-        /// the parser read `{` and started to process a JSON object
-        object_start,
-        /// the parser read `}` and finished processing a JSON object
-        object_end,
-        /// the parser read `[` and started to process a JSON array
-        array_start,
-        /// the parser read `]` and finished processing a JSON array
-        array_end,
-        /// the parser read a key of a value in an object
-        key,
-        /// the parser finished reading a JSON value
-        value
-    };
 
     using parser_callback_t =
         std::function<bool(int depth, parse_event_t event, BasicJsonType& parsed)>;
@@ -10859,23 +10862,6 @@ class basic_json
     //////////////////////////
 
     /*!
-    @brief parser event types
-
-    The parser callback distinguishes the following events:
-    - `object_start`: the parser read `{` and started to process a JSON object
-    - `key`: the parser read a key of a value in an object
-    - `object_end`: the parser read `}` and finished processing a JSON object
-    - `array_start`: the parser read `[` and started to process a JSON array
-    - `array_end`: the parser read `]` and finished processing a JSON array
-    - `value`: the parser finished reading a JSON value
-
-    @image html callback_events.png "Example when certain parse events are triggered"
-
-    @sa @ref parser_callback_t for more information and examples
-    */
-    using parse_event_t = typename parser::parse_event_t;
-
-    /*!
     @brief per-element parser callback type
 
     With a parser callback function, the result of parsing a JSON text can be
@@ -10924,7 +10910,7 @@ class basic_json
 
     @since version 1.0.0
     */
-    using parser_callback_t = typename parser::parser_callback_t;
+    using parser_callback_t = std::function<bool(int depth, detail::parse_event_t event, basic_json& parsed)>;
 
 
     //////////////////
@TurpentineDistillery
Copy link
Author

@nlohmann
Copy link
Owner

@TurpentineDistillery I'm not sure what to make of https://llvm.org/viewvc/llvm-project?view=revision&revision=259973 - is your described change in the library still required?

@TurpentineDistillery
Copy link
Author

I'll leave it to your discretion. If more people encounter this issue, then this would be a possible workaround. That said, if you don't intend to apply it, then perhaps exclude clang 3.8.0 and earlier from the list of supported compilers.

@nlohmann
Copy link
Owner

Well we successfully use clang version 3.8.0-2ubuntu3~trusty5 (tags/RELEASE_380/final) with Travis. That's why I am confused about this.

@TurpentineDistillery
Copy link
Author

Hmm, not sure what to say about this. Perhaps the compiler triggered under specific conditions only (maybe depends on libstdc++ version?). Since this does not appear to be a more widespread problem, I'll go ahead an close.

@nlohmann
Copy link
Owner

I did not mean to shut down the discussion. I just never heard of this issue before. If you do find out more details, please let me know!

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