Author Topic: tdm64-gcc compiler errors & warnings  (Read 9539 times)

Offline kaa

  • Single posting newcomer
  • *
  • Posts: 6
tdm64-gcc compiler errors & warnings
« on: April 09, 2016, 11:39:48 pm »
Hi all.  This is actually about the tdm mingw compiler rather than code::blocks specifically but since you guys recommend that compiler I hope the question is appropriate here.

So, when I try to compile the following trivial code I expect that it should produce 2 warnings and an error and should fail to compile.  In fact this is what happens when I compile it in Linux with gcc 4.8.4.

So why does it compile with no error and no warnings at all, using the same command in windows with tdm64 ver 5.1.0-2?  Is this a bug in TDM64 or mingw or do I have something configured wrong?

Code
#include <iostream>
#include <array>

using namespace std;

getSum(array<int,5>& arr)
{
    int sumIt(0);

    for(auto& elem: arr)
        sumIt += elem;
    return sumIt;
}


main()
{
    array<int,5> myInts{};
    for(int i = 0; i < 5; i++) {
        myInts[i] = i+1;
    }
    cout << getSum(myInts) << endl;
    return (0);
}






These are the compiler messages I expect (and get in Linux):
Code
$ g++ -g -Wall -Wextra -pedantic -std=c++11 -c main.cpp
main.cpp:6:25: error: ISO C++ forbids declaration of ‘getSum’ with no type [-fpermissive]
 getSum(array<int,5>& arr)
                         ^
main.cpp:16:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wpedantic]
 main()
      ^
main.cpp: In function ‘int main()’:
main.cpp:18:25: warning: missing initializer for member ‘std::array<int, 5ul>::_M_elems’ [-Wmissing-field-initializers]
     array<int,5> myInts{};
                         ^
                ^

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: tdm64-gcc compiler errors & warnings
« Reply #1 on: April 10, 2016, 01:08:14 am »
Post the full CB rebuild log!!
http://wiki.codeblocks.org/index.php/FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Till I see one; I will ignore this thread as a waste of time.

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline kaa

  • Single posting newcomer
  • *
  • Posts: 6
Re: tdm64-gcc compiler errors & warnings
« Reply #2 on: April 10, 2016, 01:25:14 am »
Sorry, I don't think this will help, but ...

Code
-------------- Build: Debug in cordova (compiler: GNU GCC Compiler)---------------

g++.exe -fexceptions -pedantic -Wextra -Wall -std=c++11  -c E:\progs\c++\cordova\main.cpp -o obj\Debug\main.o
g++.exe  -o bin\Debug\cordova.exe obj\Debug\main.o   
Output file is bin\Debug\cordova.exe with size 2.58 MB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

As I said, same command as in Linux.

It's not a Code::Blocks issue.  It compiles without errors or warnings on the command line also.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: tdm64-gcc compiler errors & warnings
« Reply #3 on: April 10, 2016, 10:36:07 am »
Are you sure you're building the correct file?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kaa

  • Single posting newcomer
  • *
  • Posts: 6
Re: tdm64-gcc compiler errors & warnings
« Reply #4 on: April 10, 2016, 09:02:49 pm »
Absolutely sure.

I've done some more testing and it turns out that not only tdm64-gcc-5.1.0-2 but also mingw-w64-x86_64-5.3.0-posix-sjlj-rt_v4-rev0
and mingw-w64-i686-5.3.0-posix-dwarf-rt_v4-rev0 all omit the no return type warning/error and the missing field initializers warning.

The same code will not compile in Visual Studio or in Linux with gcc 4.8.4.

Any ideas why the Windows gcc ports should differ on this?

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: tdm64-gcc compiler errors & warnings
« Reply #5 on: April 11, 2016, 11:35:01 am »
GCC 4.8 on your linux machine is older than your mingw GCC versions (5.1 and 5.3). Newer versions tend to be improved and have often more warnings and follow specs better.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline kaa

  • Single posting newcomer
  • *
  • Posts: 6
Re: tdm64-gcc compiler errors & warnings
« Reply #6 on: April 11, 2016, 05:03:16 pm »
The problem is the opposite: the MinGW compilers are LESS compliant with C++ standards than the older GCC compiler.

Under every C++ standard going back to 98, the compiler should at least warn that "ISO C++ forbids declaration of [function] with no type".  GCC 4.8.4 warns on declaration of main with no type but defaults to int and compiles.  But it errors on declaration of any other function with no type and refuses to compile.   And the "missing field initializers" warning should be given under -std=c++11 or later.

All 3 of these MinGW compilers compile the code with no errors, no warnings.

Here's an even simpler version of the program.  It doesn't use std::array but should still produce the same error and warning messages.  But the MinGW compilers build it with no errrors or warnings at all.
Code
#include <iostream>

struct array5 {
    int nums[5];
    int& operator[](int idx) {
        return nums[idx];
    }
    int const& operator[](int idx) const{
        return nums[idx];
    }
};

getSum(array5 arr)        // no return type ERROR
{
    int sumIt(0);
    int sz = 5;

    for(int i = 0; i < sz; i++)
        sumIt += arr[i];
    return sumIt;
}

main()                           // no return type  WARNING
{
    array5 myInts{};       //  missing field initializers   WARNING

    for(int i = 0; i < 5; i++) {
        myInts[i] = i+90;
    }

    std::cout << getSum(myInts) << std::endl;

    return (0);
}

Edited to add this code.
« Last Edit: April 11, 2016, 06:21:32 pm by kaa »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: tdm64-gcc compiler errors & warnings
« Reply #7 on: April 11, 2016, 08:25:47 pm »
What happens if you add #error "this is an error" and #warning "this is a warning" in the source file?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: tdm64-gcc compiler errors & warnings
« Reply #8 on: April 11, 2016, 08:50:13 pm »
The problem exists in MSys2 MinGW 64.
The option "-Wreturn-type" does NOT even get the warning to appear.

Code
x86_64-w64-mingw32-g++.exe (Rev1, Built by MSYS2 project) 5.3.0

I would guess the problem is in MinGW64 code.

I finally got TDM Compiler installed output below:

Code
-------------- Clean: Debug in warntest (compiler: GNU GCC Compiler MinGW64 TDM 5.1)---------------

Cleaned "warntest - Debug"
Running target pre-build steps
g++.exe --version
g++.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-------------- Build: Debug in warntest (compiler: GNU GCC Compiler MinGW64 TDM 5.1)---------------

g++.exe -Wall -fexceptions -pedantic -Wextra -Wall -std=c++11 -g -Wreturn-type -fno-permissive  -c C:\SourceCode\test\warntest\main.cpp -o obj\Debug\main.o
C:\SourceCode\test\warntest\main.cpp:15:2: warning: #warning is a GCC extension
 #warning "this is a warning"
  ^
C:\SourceCode\test\warntest\main.cpp:15:2: warning: #warning "this is a warning" [-Wcpp]
g++.exe  -o bin\Debug\warntest.exe obj\Debug\main.o   
Output file is bin\Debug\warntest.exe with size 2.61 MB
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 2 warning(s) (0 minute(s), 2 second(s))
 

Tim S.
« Last Edit: April 11, 2016, 08:59:31 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: tdm64-gcc compiler errors & warnings
« Reply #9 on: April 11, 2016, 09:50:50 pm »
-Wreturn-type is not warning about this issue, but if there is a missing return in a function that has void return type.

Anyway if there is a separate confirmation about this issue we can conclude that the only party that can explain what is happening is the people in the MinGW project. So please better direct further questions to them.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: tdm64-gcc compiler errors & warnings
« Reply #10 on: April 11, 2016, 10:51:24 pm »
-Wreturn-type is not warning about this issue, but if there is a missing return in a function that has void return type.

Anyway if there is a separate confirmation about this issue we can conclude that the only party that can explain what is happening is the people in the MinGW project. So please better direct further questions to them.

Correction Mingw64 project. I never tried with 32 bit Mingw Compiler.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline kaa

  • Single posting newcomer
  • *
  • Posts: 6
Re: tdm64-gcc compiler errors & warnings
« Reply #11 on: April 12, 2016, 12:18:29 am »
Right.  I never tried with any of the mingw.org compilers either.
I tested mingw-w64.org compilers:
x86_64-w64-mingw32-g++.exe (x86_64-5.3.0-posix-sjlj-rt_v4-rev0)
and
i686-w64-mingw32-g++.exe (i686-5.3.0-posix-dwarf-rt_v4-rev0)

and I tested x86_64-w64-mingw32-g++.exe from the latest TDM64 MinGW-w64 download which is 5.1.0-2.

So I will report it to mingw-w64 on sourceforge.

BTW obviously I haven't tested every possible warning but these are the only 2 that I've found to be missing.

Thanks for confirming.