Skip to content

[clang-tidy] Check request: portability-minmax-macro-defensive #143326

Open
@denzor200

Description

@denzor200

Needs a check that will find std::min and std::max invocations without surrounding parentheses over the name. The check will suggest to insert parentheses around the name.

BEFORE:

int result = std::min(a, b); 

AFTER:

int result = (std::min)(a, b); 

Without parentheses the code that uses std::min and std::max might lead to compilation error in MSVC:

#include <algorithm> // std::min
#include <windows.h> // min macro

int main() {
    int a = 5, b = 10;
    
    // Compilation error in MSVC: 
    // "error C2589: '(': illegal token on right side of '::'"
    int result = std::min(a, b); 
    
    return 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