Skip to content

Static initialization order fiasco in error.cpp curl_error_mapΒ #1295

@MarkRakhmatov

Description

@MarkRakhmatov

Description

I use boost/ut framework for unit testing, I create test suites as static objects (recommended by framework authors):

suite<"client"> clientTest= []{
    "login"_test = [] {
        cpr::Response getResp = cpr::Get(cpr::Url{"..."});
        ....
    };
}

It result in runtime error:

Image

It looks like static initialization order fiasco

Image

P.S. thanks for your work, it is awsome

Example/How to Reproduce

  1. Create a cpr::Response getResp = cpr::Get(cpr::Url{"..."}); with static storage duration
#include <cpr/cpr.h>

cpr::Response getResp = cpr::Get(cpr::Url{"https://example-website.com"});
  1. See error

Possible Fix

Please, consider replacing static unordered_map with function like this:

ErrorCode curl_error_to_error_code(std::int32_t curl_error) {
    switch (curl_error) {
        case CURLE_OK:
            return ErrorCode::OK;
        // and so on ...
        default:
            return ErrorCode::TOO_LARGE;
            
    }
}

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: Windows 11
  • Version: 1.12.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions