Skip to content

Instantly share code, notes, and snippets.

@colematt
Last active February 14, 2024 18:35
Show Gist options
  • Save colematt/d93793ec10934be7d142f0365e5b7ec0 to your computer and use it in GitHub Desktop.
Save colematt/d93793ec10934be7d142f0365e5b7ec0 to your computer and use it in GitHub Desktop.
[Fix ‘numeric_limits’ is not a member of ‘std’ error in LLVM 10.0] #llvm

Fix ‘numeric_limits’ is not a member of ‘std’ error in LLVM 10.0

This problem has been verified in both of the LLVM 10.0.0 and 10.0.1 releases' monorepos. The problem and fix is shown for 10.0.1, but the patch can be applied to a 10.0.0 monorepo.

Problem

[3273/3351] Building CXX object utils/.../benchmark.dir/benchmark_register.cc.o
FAILED: utils/benchmark/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o 
/usr/bin/c++ -DHAVE_POSIX_REGEX -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dbenchmark_EXPORTS -I/home/matthew/llvm-project-10.0.1/build/utils/benchmark/src -I/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src -I/usr/include/libxml2 -I/home/matthew/llvm-project-10.0.1/build/include -I/home/matthew/llvm-project-10.0.1/llvm/include -I/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/include -I/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/../include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color  -std=c++11  -Wall  -Wextra  -Wshadow  -pedantic  -pedantic-errors  -Wfloat-equal  -fstrict-aliasing  -fno-exceptions  -Wstrict-aliasing -g -fPIC -std=c++14 -MD -MT utils/benchmark/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o -MF utils/benchmark/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o.d -o utils/benchmark/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o -c /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.cc
In file included from /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.cc:15:
/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h: In function ‘void AddRange(std::vector<T>*, T, T, int)’:
/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h:17:30: error: ‘numeric_limits’ is not a member of ‘std’
   17 |   static const T kmax = std::numeric_limits<T>::max();
      |                              ^~~~~~~~~~~~~~
/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h:17:46: error: expected primary-expression before ‘>’ token
   17 |   static const T kmax = std::numeric_limits<T>::max();
      |                                              ^
/home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h:17:49: error: ‘::max’ has not been declared; did you mean ‘std::max’?
   17 |   static const T kmax = std::numeric_limits<T>::max();
      |                                                 ^~~
      |                                                 std::max
In file included from /usr/include/c++/11/algorithm:62,
                 from /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/include/benchmark/benchmark.h:175,
                 from /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/internal_macros.h:4,
                 from /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/check.h:8,
                 from /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h:6,
                 from /home/matthew/llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.cc:15:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: ‘std::max’ declared here
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
[3282/3351] Building CXX object unitte...psTests.dir/SnippetGeneratorTest.cpp.o
ninja: build stopped: subcommand failed.

Solution

  1. Place llvm-project-10.0.1.patch in the same directory as the LLVM project source monorepo.
  2. Apply the patch:
matthew@localhost:~$ ls -l | grep llvm
drwxr-xr-x 21 matthew matthew   4096 Jul 21  2020 llvm-project-10.0.1
-rw-rw-r--  1 matthew matthew    517 Feb 14 13:06 llvm-project-10.0.1.patch
matthew@localhost:~$ patch -p1 < llvm-project-10.0.1.patch
patching file llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h
matthew@localhost:~$
diff -Naur ./llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h ./llvm-project-10.0.1-patched/llvm/utils/benchmark/src/benchmark_register.h
--- ./llvm-project-10.0.1/llvm/utils/benchmark/src/benchmark_register.h 2020-07-07 12:21:37.000000000 -0400
+++ ./llvm-project-10.0.1-patched/llvm/utils/benchmark/src/benchmark_register.h 2024-02-14 13:02:20.696010829 -0500
@@ -1,6 +1,7 @@
#ifndef BENCHMARK_REGISTER_H
#define BENCHMARK_REGISTER_H
+#include <limits>
#include <vector>
#include "check.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment