[llvm-bugs] [Bug 40349] New: "max" and "min" in std namespace even when <algorithm> not included

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 16 22:35:43 PST 2019


            Bug ID: 40349
           Summary: "max" and "min" in std namespace even when <algorithm>
                    not included
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andi.m.mcclure at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com


Here's a simple program.


#include <array>

int main() {
        int x = std::max(3, 4);
        return x;


For purposes of this repro, it appears you can replace <map> with literally any
STL header, <iostream>, <map>, <string>, as far as I can tell anything.

I performed this test both on my local computer (OS X 10.13.2, Apple LLVM
version 9.0.0 (clang-900.0.39.2) target x86_64-apple-darwin17.3.0) and on
"godbolt.org", where I tested it with "x86-64 clang 7.0.0 " and tested with and
without each of -stdlib=libc++ and -stdlib=libstdc++ and with and without


Program compiles. Returns status code 4 when run.


This program should not compile. Both cppreference.com and the N3242 draft
standard for C++ place std::max and std::min in <algorithm>. N3242 specifies
that <array>, <map> and <string> should all include <initializer_list> and
lists no other includes. There is no reason why std::max would be accessible.


When Clang is loosey goosey about following the standard but MSVC is strict,
this creates problems for me because I accidentally write noncompliant code,
run it for long periods locally believing it is correct code, and then as soon
as I check out and build on Windows I discover I have to perform a bunch of
modifications. (I have filed another bug,
https://bugs.llvm.org/show_bug.cgi?id=40347 , which goes into some detail as to
why this is bad for me.) The program up top does NOT compile on Visual Studio
15.0 (Aka Visual Studio 2017).

MSVC has not always been as good about following the standards as it is right
now. However, one thing MSVC has been consistent about for a LONG time has been
that std::max and std::min ALWAYS require <algorithm> to be included, and I
ALWAYS forget to require <algorithm> because I'm locally using clang, and so
the minute I check out new code on Windows I have to run around adding #include
<algorithm>. This specific thing has been an annoyance for years.


Maybe there is some good reason clang/libc++ does not follow the standard on
this, such as backward compatibility. I personally do find it annoying to have
to include <algorithm> and when casually coding I like it that std::max and
std::min are always just there. BUT, if this behavior is as-intended, I would
like to have some way of getting a standard-compliant STL *on-demand*, such as
a documented command-line argument to clang "-stdlib=please actually follow the
standard", so I can get consistency across platforms.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190117/faba8be6/attachment-0001.html>

More information about the llvm-bugs mailing list