简体   繁体   中英

MinGW-w64 compilation fails with nullptr_t

I'm trying to compile cpputest with MinGHW-w64 and it's failing because it can't find nullptr_t. The function that is failing is cpputest\\src\\CppUTest\\SimpleString.cpp:StringFrom

SimpleString StringFrom(const nullptr_t value)
{
    (void) value;
    return "(null)";
}

I tried to manually compile this file with

C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe -DCPPUTEST_HAVE_STRDUP=1 -DHAVE_CONFIG_H -D_TIMESPEC_DEFINED=1 @CMakeFiles/CppUTest.dir/includes_CXX.rsp -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h" -std=c++11 -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast -Wno-c++14-compat -O2 -g -DNDEBUG -o CMakeFiles\\CppUTest.dir\\SimpleString.cpp.obj -c C:\\git\\tdd\\cpputest\\src\\CppUTest\\SimpleString.cpp

It fails with

C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:565:31: error: 'nullptr_t' does not name a type
 SimpleString StringFrom(const nullptr_t value)
                               ^~~~~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:565:31: note: 'nullptr_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:32:1:
+#include <cstddef>

C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:565:31:
 SimpleString StringFrom(const nullptr_t value)
                               ^~~~~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:565:14: error: redefinition of 'SimpleString StringFrom(int)'
 SimpleString StringFrom(const nullptr_t value)
              ^~~~~~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:479:14: note: 'SimpleString StringFrom(int)' previously defined here
 SimpleString StringFrom(int value)
              ^~~~~~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp: In function 'SimpleString StringFrom(cpputest_longlong)':
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:576:29: warning: unknown conversion type character 'l' in format [-Wformat=]
     return StringFromFormat("%lld", value);
                             ^~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:576:29: warning: too many arguments for format [-Wformat-extra-args]
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp: In function 'SimpleString StringFrom(cpputest_ulonglong)':
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:581:29: warning: unknown conversion type character 'l' in format [-Wformat=]
     return StringFromFormat("%llu", value);
                             ^~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:581:29: warning: too many arguments for format [-Wformat-extra-args]
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp: In function 'SimpleString HexStringFrom(cpputest_longlong)':
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:586:29: warning: unknown conversion type character 'l' in format [-Wformat=]
     return StringFromFormat("%llx", value);
                             ^~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:586:29: warning: too many arguments for format [-Wformat-extra-args]
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp: In function 'SimpleString HexStringFrom(cpputest_ulonglong)':
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:591:29: warning: unknown conversion type character 'l' in format [-Wformat=]
     return StringFromFormat("%llx", value);
                             ^~~~~~
C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:591:29: warning: too many arguments for format [-Wformat-extra-args]

I tried the naive solution of including cstddef:

#include <cstddef>

SimpleString StringFrom(const nullptr_t value)
{
    (void) value;
    return "(null)";
}

But that fails with the same error:

C:\git\tdd\cpputest\src\CppUTest\SimpleString.cpp:568:31: error: 'nullptr_t' does not name a type
 SimpleString StringFrom(const nullptr_t value)

This error doesn't make any sense as I'm including cstddef.

This problem is related with this question .

Any help is appreciated!

The fix is simple enough:

SimpleString StringFrom(const std::nullptr_t value)
{
    (void) value;
    return "(null)";
}

Thanks for NathanOliver- Reinstate Monica for helping to figure this out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM