Skip to content

fmtlog not working in constexpr function #104

@zcuder

Description

@zcuder
constexpr void log_custom() {
    constexpr char randomString[] = "Hello World";
    logi("A string, pointer, number, and float: '{}', {}, {}, {} {}", randomString);
}

编译报错
~/fmtlog/test/log_test.cc: In function ‘constexpr void log_custom()’:
~/fmtlog/test/../fmtlog.h:758:21: error: ‘logId’ declared ‘static’ in ‘constexpr’ function
758 | static uint32_t logId = 0;
| ^~~~~
~/fmtlog/test/../fmtlog.h:793:27: note: in expansion of macro ‘FMTLOG’
793 | #define logi(format, ...) FMTLOG(fmtlog::INF, format, ##VA_ARGS)
| ^~~~~~
~/fmtlog/test/log_test.cc:31:5: note: in expansion of macro ‘logi’
31 | logi("A string, pointer, number, and float: '{}', {}, {}, {} {}", randomString);
看样子在constexpr函数内FMTLOG宏定义的logId不是constexpr变量而且是static的,有没有办法支持constexpr function?

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