-2

It's a simple question really, and refers to Linux (as opposed to Windows or Mac).

How do you generate a warning message from the C or C++ compiler that must have the word 'suspicious' in it, and must refer to (-Wmain).


(update)

Thanks Boann - I got some of those Warnings, but I also got Error - error: ‘::main’ must return ‘int’.

The reason I'm asking this question is that a week ago my compiler (GCC 4.8.1) came out with this warning saying 'suspicious' and that it was caused by Wmain. So I put -Wno-main and the warning went away and it compiled fine. Just recently it has started complaining making it an actual Error and not compiling. So I'm kind of worried that somehow the mother ship has covertly updated my compiler over the internet, without me knowing, and changed it to treat it as error. (I was probably using 'int4' as the return type which I forever have typedef'd as signed long int.

I note there's -Wmain referenced in g++ man page so it must be for something, but what warning is there that isn't overruled by an error??


At offset 557284 (decimal) of the g++ executable I found "Warn about suspicious declarations of "main".

Clive
  • 269
  • 1
  • 14
  • 7
    `#pragma message "This warning is suspicious. [-Wmain]"` – chris Aug 24 '14 at 19:20
  • 3
    What an odd question. – Benjamin Lindley Aug 24 '14 at 19:30
  • Note that GCC documentation defines: `-Wmain` _Warn if the type of ‘main’ is suspicious. ‘main’ should be a function with external linkage, returning int, taking either zero arguments, two, or three arguments of appropriate types. This warning is enabled by default in C++ and is enabled by either `-Wall` or `-Wpedantic`._ However, the warnings generated (or errors if you use `-Werror`) do not contain 'suspicious'. – Jonathan Leffler Aug 24 '14 at 19:50
  • chris - That's kind of 'cheating'! – Clive Aug 24 '14 at 20:01
  • Why do you need this? Knowing the reason behind the question would be very helpful in coming up with a useful answer; for example, chris's comment meets your stated requirements, but we can't guess whether it's what you need. Is there a *practical* requirement? – Keith Thompson Aug 24 '14 at 20:03
  • Jonathan - thanks, I'm not sure that the compiler is keeping to what the documentation says though. I get it as an Error not a warning. – Clive Aug 24 '14 at 20:03
  • 1
    Unless you can explain **why** you're trying to get this warning message to solve a problem (e.g. trick some bogus configure script), I think this question belongs on codegolf.stackexchange.com rather than SO.. :-) – R.. GitHub STOP HELPING ICE Aug 24 '14 at 20:12
  • 1
    @chris: Shouldn't that be an answer? – R.. GitHub STOP HELPING ICE Aug 24 '14 at 20:13
  • @R.., I wasn't really sure what the question was asking for :p – chris Aug 24 '14 at 20:17
  • 1
    @chris: It's sufficiently funny and actually answers the question as written, so I'd upvote it. :-) – R.. GitHub STOP HELPING ICE Aug 24 '14 at 20:20
  • Keith - thanks, I need to know because it came with just the Warning a week ago, and now it's reporting an error. There would be no point in giving the warning if it was going to give an error complaining main's return type wasn't int. It's like my compiler has been changed. I've tried to explain why I want to be able to re-create this warning in an update above. – Clive Aug 24 '14 at 20:22
  • 1
    That `error: ‘::main’ must return ‘int’` looks very C++ish. Perhaps you compiled as C before? (It isn't portable to return non-`int` in C either, though.) – mafso Aug 24 '14 at 23:59

3 Answers3

2

For what it's worth,

struct suspicious {};

int main(suspicious) {}

Output with g++ -Wall, GCC 4.8.2:

warning: first argument of 'int main(suspicious)' should be 'int' [-Wmain]

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
1

If you refer to the -Wmain parameter of GCC, you get the warning by giving main odd arguments, an odd return type, or giving it static linkage. This will do it:

static float main(float x) {
    return 0;
}

Compiled with gcc -Wmain, it displays these warnings; they do not actually contain the word 'suspicious' though:

warning: return type of 'main' is not 'int'
warning: first argument of 'main' should be 'int'
warning: 'main' takes only zero or two arguments
warning: 'main' is normally a non-static function
Boann
  • 48,794
  • 16
  • 117
  • 146
  • 1
    That message does not contain the word "suspicious". I have no idea why that's a requirement, but this doesn't answer the question as stated. – Keith Thompson Aug 24 '14 at 20:00
  • Thanks Boann - I got some of those Warnings, but I also got Error - error: ‘::main’ must return ‘int’. The reason I'm asking this question is that - (not enough space here, I'll update above - – Clive Aug 24 '14 at 20:13
  • I suspect the desired warning message exists only in very specific GCC versions. One could grep the gcc repo commit log (huge and unwieldy) to find it, if really desired. – R.. GitHub STOP HELPING ICE Aug 24 '14 at 20:21
  • R, - thanks. Could installing a package (rpm) of Qt5 have changed my GCC version? – Clive Aug 24 '14 at 20:35
1

I just downloaded the sources for gcc 4.8.1 and searched all relevant files for the word "suspicious".

There are a number of occurrences, but as far as I can tell, there's no way an error message for a C or C++ source file can contain the word "suspicious". It's possible but unlikely that there was a local modification.

Is it possible that you're mistaken about what the error message said? If you have a log containing the error message, please update your question to show the exact message your received.

If you're concerned that your compiler may have been updated without your knowledge, you might check the timestamp of the compiler executable and of any programs it invokes (use gcc -v to check that). But gcc itself doesn't automatically update itself. If you're using it on a system administered by someone else, automatic updates are to be expected. If you administer the system yourself, you may have configured it to update software without manual intervention; if so, that's not a gcc issue. I don't know what "mother ship" you're referring to.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • Using your link I also downloaded the 4.8.1 version and found "suspicious" near to "Wmain" only in what I guess are documentation files. – Clive Aug 26 '14 at 03:30
  • Thank you very much for taking the time to do it. I suppose I must be mistaken, unless I was running Qt and they have amended the compiler. I've checked the date of the compiler and in the -v output and the directory listing it both says 3/6/2013. By "mother ship" I was tongue-in-cheek referring to the Fedora Project, Bugzilla, GNU, Trolltech, or any other! – Clive Aug 26 '14 at 03:41
  • A question still in my mind though is how people are saying it's a Warning, when on my machine it comes up as Error - error: ‘::main’ must return ‘int’. Sure, you can get Warning entering 'float main' (which I wouldn't have been stupid enough to do) but it also comes with the Error. Whereas I'm pretty sure I amended the compile line to -Wno-main and it then compiled. – Clive Aug 26 '14 at 03:47