Skip to content

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

@TurpentineDistillery

Description

@TurpentineDistillery

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)>;
 
 
     //////////////////

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions