MinGW-w64 compilation fails with nullptr_t - c++

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.

Related

C++ API for LLVM library generates too many warnings

I am not sure if I am the only person or this is the problem of so many other people.
What I suffer from is that for an even simple code that includes LLVM headers regardless of what ever I write in my main function, I get too many warnings when I compile my codes with extra warnings:
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/Instructions.h>
int main()
{
return 0;
}
I cat get these warnings by using either gcc or clang:
g++-9 -std=c++17 main.cpp -Wall -Wextra -I/usr/lib/llvm-9/include -c -o main.o
clang++-9 -std=c++17 main.cpp -Wall -Wextra -I/usr/lib/llvm-9/include -c -o main.o
They are mainly unused parameters:
In file included from /usr/lib/llvm-9/include/llvm/IR/ConstantFolder.h:20,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:24,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/IR/Constants.h: In member function ‘llvm::Value* llvm::ConstantData::handleOperandChangeImpl(llvm::Value*, llvm::Value*)’:
/usr/lib/llvm-9/include/llvm/IR/Constants.h:60:41: warning: unused parameter ‘From’ [-Wunused-parameter]
60 | Value *handleOperandChangeImpl(Value *From, Value *To) {
| ~~~~~~~^~~~
/usr/lib/llvm-9/include/llvm/IR/Constants.h:60:54: warning: unused parameter ‘To’ [-Wunused-parameter]
60 | Value *handleOperandChangeImpl(Value *From, Value *To) {
| ~~~~~~~^~
In file included from /usr/lib/llvm-9/include/llvm/IR/ConstantFolder.h:21,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:24,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/IR/InstrTypes.h: In member function ‘bool llvm::CallBase::isFnAttrDisallowedByOpBundle(llvm::StringRef) const’:
/usr/lib/llvm-9/include/llvm/IR/InstrTypes.h:1913:47: warning: unused parameter ‘S’ [-Wunused-parameter]
1913 | bool isFnAttrDisallowedByOpBundle(StringRef S) const {
| ~~~~~~~~~~^
In file included from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:33,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/IR/Instructions.h: In member function ‘llvm::BasicBlock* llvm::ReturnInst::getSuccessor(unsigned int) const’:
/usr/lib/llvm-9/include/llvm/IR/Instructions.h:2943:37: warning: unused parameter ‘idx’ [-Wunused-parameter]
2943 | BasicBlock *getSuccessor(unsigned idx) const {
| ~~~~~~~~~^~~
...
I just truncate these warnings. They are too many.
When I turn on the -Wconversion the problem becomes even worse:
In file included from /usr/lib/llvm-9/include/llvm/Support/MathExtras.h:17,
from /usr/lib/llvm-9/include/llvm/ADT/SmallVector.h:19,
from /usr/lib/llvm-9/include/llvm/ADT/STLExtras.h:20,
from /usr/lib/llvm-9/include/llvm/ADT/StringRef.h:12,
from /usr/lib/llvm-9/include/llvm/ADT/StringMap.h:16,
from /usr/lib/llvm-9/include/llvm/Support/Host.h:16,
from /usr/lib/llvm-9/include/llvm/ADT/Hashing.h:48,
from /usr/lib/llvm-9/include/llvm/ADT/ArrayRef.h:12,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:18,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/Support/SwapByteOrder.h: In function ‘uint16_t llvm::sys::SwapByteOrder_16(uint16_t)’:
/usr/lib/llvm-9/include/llvm/Support/SwapByteOrder.h:36:23: warning: conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value [-Wconversion]
36 | uint16_t Hi = value << 8;
| ~~~~~~^~~~
/usr/lib/llvm-9/include/llvm/Support/SwapByteOrder.h:37:23: warning: conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} may change value [-Wconversion]
37 | uint16_t Lo = value >> 8;
| ~~~~~~^~~~
In file included from /usr/lib/llvm-9/include/llvm/ADT/STLExtras.h:20,
from /usr/lib/llvm-9/include/llvm/ADT/StringRef.h:12,
from /usr/lib/llvm-9/include/llvm/ADT/StringMap.h:16,
from /usr/lib/llvm-9/include/llvm/Support/Host.h:16,
from /usr/lib/llvm-9/include/llvm/ADT/Hashing.h:48,
from /usr/lib/llvm-9/include/llvm/ADT/ArrayRef.h:12,
from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:18,
from main.cpp:1:
/usr/lib/llvm-9/include/llvm/ADT/SmallVector.h: In constructor ‘llvm::SmallVectorBase::SmallVectorBase(void*, size_t)’:
/usr/lib/llvm-9/include/llvm/ADT/SmallVector.h:45:35: warning: conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘unsigned int’ may change value [-Wconversion]
45 | : BeginX(FirstEl), Capacity(TotalCapacity) {}
| ^~~~~~~~~~~~~
...
I get these warnings by clang too:
...
In file included from main.cpp:1:
In file included from /usr/lib/llvm-9/include/llvm/IR/IRBuilder.h:18:
In file included from /usr/lib/llvm-9/include/llvm/ADT/ArrayRef.h:12:
/usr/lib/llvm-9/include/llvm/ADT/Hashing.h:190:15: warning: implicit conversion changes signedness: 'const char' to 'uint8_t' (aka 'unsigned char') [-Wsign-conversion]
uint8_t a = s[0];
~ ^~~~
/usr/lib/llvm-9/include/llvm/ADT/Hashing.h:191:15: warning: implicit conversion changes signedness: 'const char' to 'uint8_t' (aka 'unsigned char') [-Wsign-conversion]
uint8_t b = s[len >> 1];
~ ^~~~~~~~~~~
/usr/lib/llvm-9/include/llvm/ADT/Hashing.h:192:15: warning: implicit conversion changes signedness: 'const char' to 'uint8_t' (aka 'unsigned char') [-Wsign-conversion]
uint8_t c = s[len - 1];
~ ^~~~~~~~~~
...
This is just a MWE. Adding more headers, I can get other types of warnings such as
/usr/lib/llvm-9/include/llvm/ADT/Twine.h:232:16: warning: ‘<anonymous>.llvm::Twine::RHS.llvm::Twine::Child::twine’ may be used uninitialized in this function [-Wmaybe-uninitialized]
!RHS.twine->isBinary())
~~~~^~~~~
Now, I am wondering whether LLVM is written carelessly? I always turn on all warnings and make sure my application compiles with 0 warnings. When I do this while using LLVM all warnings of my code are burried under LLVM ones. I cannot easily see them. Usually the first advise from people is to turn off those warnings switches. I strictly resist that. I want to find them for my application. The alternative solution comes to my mind is to turn off these warnings only for LLVM but not for my application. Is this possible especially when using CMake?
The issue of system header files causing warnings is a common one. It is not really for me to judge whether the authors of those headers were "careless" or not, but there is a relatively simple way to disable specific warnings before including the 'offending' headers, then restore your 'full' warnings once they have been included.
For clang you can do this with various #pragma diagnostic ... lines, as shown in the following code snippet:
#if defined (__clang__)
#pragma clang diagnostic push // Saves current diagnostic settings
#pragma clang diagnostic ignored "-Wsign-conversion" // Ignore this warning
#pragma clang diagnostic ignored "-Wunused-parameter" // and this one...
// ... Add similar lines for other warnings you wish to disable
#endif
// Now include the 'offending' headers ...
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/Instructions.h>
#if defined(__clang__)
#pragma clang diagnostic pop // Restores the saved settings
#endif
I don't have access to a GCC compiler but I believe very similar directives can be used: just substitute GCC for clang in the lines where that occurs. More information on such #pragma directives (for the GCC versions) can be found here.
It is dependent on your GCC/clang/OS installation. On Fedora 32 it works as expected out of the box with system gcc-10.2.1-1.fc32.x86_64 + system clang-10.0.0-2.fc32.x86_64:
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/IR/Instructions.h>
static void func(int val) {}
int main()
{
func(42);
return 0;
}
For GCC:
$ g++ -o stackoverflowllvmwarnings stackoverflowllvmwarnings.C $(llvm-config --cflags --libs) -std=c++17 -Wall -Wextra
stackoverflowllvmwarnings.C: In function ‘void func(int)’:
stackoverflowllvmwarnings.C:7:22: warning: unused parameter ‘val’ [-Wunused-parameter]
7 | static void func(int val) {}
| ~~~~^~~
$ _
For clang:
$ clang++ -o stackoverflowllvmwarnings stackoverflowllvmwarnings.C $(llvm-config --cflags --libs) -std=c++17 -Wall -Wextra
stackoverflowllvmwarnings.C:7:22: warning: unused parameter 'val' [-Wunused-parameter]
static void func(int val) {}
^
1 warning generated.
$ _
If you really want (you do not) the warnings even for system headers use Wsystem-headers (it works similar way both for gcc and clang):
$ clang++ -o stackoverflowllvmwarnings stackoverflowllvmwarnings.C $(llvm-config --cflags --libs) -std=c++17 -Wall -Wextra -Wsystem-headers
In file included from stackoverflowllvmwarnings.C:1:
In file included from /usr/include/llvm/IR/IRBuilder.h:17:
In file included from /usr/include/llvm-c/Types.h:17:
In file included from /usr/include/llvm-c/DataTypes.h:28:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/cmath:42:
/usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/bits/cpp_type_traits.h:110:12: warning: keyword '__is_void' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
struct __is_void
^
...

Unable to build wxWidgets on Cygwin - xlocale.h

I've been attempting to build wxWidgets 3.1.0 in Cygwin. I followed the process described in the install.txt, summarized below:
cd $WXWIN
mkdir build-debug
cd build-debug
../configure --enable-debug
make -j4
I have also tried a couple other flags for configure such as --with-X11, as suggest by this guide. The error I keep receiving, however, is the following:
/home/acohen8/wxWidgets-3.1.0/build-debug/bk-deps g++ -c -o basedll_strvararg.o -D__WXMSW__ -DWXBUILDING -I../src/regex -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/acohen8/wxWidgets-3.1.0/build-debug/lib/wx/include/msw-unicode-3.1 -I../include -g -O0 ../src/common/strvararg.cpp
In file included from ../src/common/string.cpp:39:0:
../include/wx/xlocale.h: In function ‘double wxStrtod_lA(const char*, char**, const wxXLocale&)’:
../include/wx/xlocale.h:243:54: error: ‘strtod_l’ was not declared in this scope
{ return wxCRT_Strtod_lA(c, endptr, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long int wxStrtol_lA(const char*, char**, int, const wxXLocale&)’:
../include/wx/xlocale.h:245:60: error: ‘strtol_l’ was not declared in this scope
{ return wxCRT_Strtol_lA(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long unsigned int wxStrtoul_lA(const char*, char**, int, const wxXLocale&)’:
../include/wx/xlocale.h:247:61: error: ‘strtoul_l’ was not declared in this scope
{ return wxCRT_Strtoul_lA(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘double wxStrtod_l(const wchar_t*, wchar_t**, const wxXLocale&)’:
../include/wx/xlocale.h:301:58: error: ‘wcstod_l’ was not declared in this scope
{ return wxCRT_Strtod_lW(c, endptr, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long int wxStrtol_l(const wchar_t*, wchar_t**, int, const wxXLocale&)’:
../include/wx/xlocale.h:303:64: error: ‘wcstol_l’ was not declared in this scope
{ return wxCRT_Strtol_lW(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long unsigned int wxStrtoul_l(const wchar_t*, wchar_t**, int, const wxXLocale&)’:
../include/wx/xlocale.h:305:65: error: ‘wcstoul_l’ was not declared in this scope
{ return wxCRT_Strtoul_lW(c, endptr, base, loc.Get()); }
^
/home/acohen8/wxWidgets-3.1.0/build-debug/bk-deps g++ -c -o basedll_sysopt.o -D__WXMSW__ -DWXBUILDING -I../src/regex -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/acohen8/wxWidgets-3.1.0/build-debug/lib/wx/include/msw-unicode-3.1 -I../include -g -O0 ../src/common/sysopt.cpp
make: *** [Makefile:25366: basedll_string.o] Error 1
make: *** Waiting for unfinished jobs....
I would very much appreciate some suggestions on this!
This is most likely already fixed in wx's git master by this commit. But you can work around the problem by using configure --disable-xlocale.

How to test for std::showbase or std::noshowbase in output operator?

I have a big integer class, and I'm trying to make it honor std::showbase and std::noshowbase. Here, "honor" means to control the use of a suffix as defined in the Integer class (and not the C++ standard behaviors):
std::ostream& operator<<(std::ostream& out, const Integer &a)
{
...
if(out.flags() & std::noshowbase)
return out;
return out << suffix;
}
However, it results in an error:
$ make static
c++ -DDEBUG -g3 -O1 -fPIC -Wno-tautological-compare -Wno-unused-value -DCRYPTOPP_DISABLE_ASM -pipe -c integer.cpp
integer.cpp:3487:17: error: invalid operands to binary expression ('int' and
'std::ios_base &(*)(std::ios_base &)')
if(out.flags() & std::noshowbase)
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
/usr/include/c++/4.2.1/bits/ios_base.h:79:3: note: candidate function not
viable: no known conversion from 'std::ios_base &(std::ios_base &)' to
'std::_Ios_Fmtflags' for 2nd argument
operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
^
1 error generated.
I've also tried std::ios::noshowbase and std::ios_base::noshowbase with similar errors.
How does one test for showbase and noshowbase?
noshowbase is a function, not an integral of bitmask type. There's also no ios_base::noshowbase. But there is ios_base::showbase. Maybe you wanted:
if (out.flags() & std::ios_base::showbase) {
return out << suffix;
}
return out;

g++ -Wall not warning about double-> int cast

In the following snippet no warnings are produced. g++4.4.3 -Wall -pedantic
//f is
void f(int );
f(3.14);
double d = 3.14;
int i = d+2;
I have a strong recollection of this being a warning, something along the lines of "Possible loss of precision". Was it removed or is my memory playing tricks on me?
How can i turn this into a warning in g++? I find this a useful warning, or is it a bad idea?
I can't even find anything appropriate at http://gcc.gnu.org/onlinedocs/gcc-4.4.5/gcc/Warning-Options.html
$ gcc -Wconversion test.c
test.c: In function ‘main’:
test.c:3: warning: conversion to ‘int’ from ‘double’ may alter its value
Use -Wconversion option. -Wall doesn't include it.
With -Wconversion option, GCC gives these warning messages:
warning: conversion to 'int' alters 'double' constant value
warning: conversion to 'int' from 'double' may alter its value
Apart from what other answers mention it is also worth mentioning that in C++0x {} initialization doesn't narrow. So instead of getting a warning you'll get an error for example
void f(int x)
{
// code
}
int main()
{
f({3.14}); // narrowing conversion of '3.14000000000000012434497875801753252744674682617e+0' from 'double' to 'int' inside { }
}
g++ 4.4 and above support initializer list (with -std=c++0x option)

Using size of one array in another array

// sizeofarray.cpp
#include <iostream>
template <typename T,int N>
int size(T (&Array)[N])
{
return N;
}
int main()
{
char p[]="Je suis trop bon, et vous?";
char q[size(p)]; // (A)
return 0;
}
I heard that an array size in C++ must be a constant expression. So char q[size(p)] is invalid, am I right? But I got no errors when I tried
g++ -Wall sizeofarray.cpp
Why?
Like Prasoon says, it's not a constant expression. For now, you can get a constant-expression value of the size of an array like this:
template <std::size_t N>
struct type_of_size
{
typedef char type[N];
};
template <typename T, std::size_t Size>
typename type_of_size<Size>::type& sizeof_array_helper(T(&)[Size]);
#define sizeof_array(pArray) sizeof(sizeof_array_helper(pArray))
Explanation here. You basically encode the size of the array into the size of a type, then get the sizeof of that type, giving you:
char q[sizeof_array(p)];
I heard that an array size in C++ must be a constant expression.
Correct
So char q[size(p)] is invalid, am I right?
According to ISO C++, yes!
But I got no errors when I tried
g++ -Wall sizeofarray.cpp
That's because g++ supports VLA (Variable Length Array) as an extension.
In C++0x there is constexpr feature with the help of which you can write
constexpr int size(T (&Array)[N])
{
return N;
}
and then char q[size(p)] would be legal.
EDIT : Also read this article [blog whatever]
I beg to differ with all the answers here. The code show is perfectly fine except for a minor issue (which is definitely not VLA)
template <typename T,int N>
int size(T (&Array)[N])
{
return N;
}
int main()
{
char p[]="Je suis trop bon, et vous?";
char q[sizeof(p)]; // (A), not sizeof and not size as in OP
return 0;
}
I was wondering that the result of the sizeof is always a const value, and hence the code should be fine.
The above code builds fine on VS 2010 and Comeau(strict mode)
$5.3.3/6- "The result is a constant of
type size_t. [Note: size_t is defined
in the standard header (18.1)."
I use g++ 4.4.3 and have the following alias so that I never forget to turn on the warnings:
$ alias g++
alias g++='g++ -ansi -pedantic -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings'
If compiled with the above, there would be some warnings. Following steps show how different options show different warnings.
Compilation with no warning option does not show any warning
$ \g++ sizeofarray.cpp
Turning on -Wall
$ \g++ -Wall sizeofarray.cpp
sizeofarray.cpp: In function ‘int main()’:
sizeofarray.cpp:12: warning: unused variable ‘q’
Turning on -Wextra
$ \g++ -Wall -Wextra sizeofarray.cpp
sizeofarray.cpp: In function ‘int main()’:
sizeofarray.cpp:12: warning: unused variable ‘q’
sizeofarray.cpp: At global scope:
sizeofarray.cpp: In instantiation of ‘int size(T (&)[N]) [with T = char, int N = 27]’:
sizeofarray.cpp:12: instantiated from here
sizeofarray.cpp:4: warning: unused parameter ‘Array’
Finally turning on -pedantic to catch the real problem
$ \g++ -Wall -Wextra -pedantic sizeofarray.cpp
sizeofarray.cpp: In function ‘int main()’:
sizeofarray.cpp:12: warning: ISO C++ forbids variable length array ‘q’
sizeofarray.cpp:12: warning: unused variable ‘q’
sizeofarray.cpp: At global scope:
sizeofarray.cpp: In instantiation of ‘int size(T (&)[N]) [with T = char, int N = 27]’:
sizeofarray.cpp:12: instantiated from here
sizeofarray.cpp:4: warning: unused parameter ‘Array’