51

Recently, I wanted to ask a question concerning C++ code that did not compile with g++. Just before posting the question, I thought: "Maybe this is a bug in g++?" and tried with Clang and it worked.

After searching a bit, I did not find any clear answer on which of the compilers is right - a bug in g++ or a non-standard feature in Clang.

Would it be on-topic to ask on Stack Overflow if such behavior is a bug in g++ or not (e.g. something that is not standard)?

7
  • 35
    I think your real question is "Why does this code exhibit different behavior when compiled with these two compilers?" and that's pretty clearly on-topic, regardless of whether it's a bug in your code, in a compiler, or in the language standard, or an extension or other implementation-defined behavior. Commented Mar 30, 2016 at 2:35
  • 8
    I think a significant percentage of my questions are of the form "gcc and clang do different things with this mcve. what's up, SO language wizards?"
    – Barry
    Commented Mar 30, 2016 at 2:38
  • 1
    Sure, compilers are definitely tools used for programming. Therefore they are on-topic. Commented Mar 31, 2016 at 13:10
  • This question asked pretty much the same, and it seem to be well received.
    – user2535467
    Commented Mar 31, 2016 at 13:13
  • I also found that it's OK to ask why code behaves different on different devices/versions.
    – Laurel
    Commented Mar 31, 2016 at 19:26
  • Compiler bugs causing valid code not to compile or incorrect behavior of compiled code is not like a bug in Solitaire which messes up the suit colors. The former has everything to do with developing software, and the latter - only if you somehow work with code related to Solitaire. So they're not the same kind of question and this question is not a dupe!
    – einpoklum
    Commented Mar 1, 2020 at 9:14
  • For example, if there is some like a "solitaire API", and you have a programming problem about it (including api/compiler bugs), that is ontopic. "Why my solitaire crashes" is not. But, the problem in your question is ontopic in all the cases.
    – peterh
    Commented Mar 1, 2020 at 11:29

3 Answers 3

71

You can ask a question asking why the behavior of the two compilers is different if you don't understand it - there are a lot of questions like that already. Make sure your example is self-contained, so that it is easy to reproduce, and mention the versions of the compilers and standard C++ library you're using.

But be careful with labeling it as a bug - could be a different interpretation of the standard by the two implementations (which could make it a "standards bug"/ambiguity of sorts), or could be that your code is wrong and one of them doesn't catch the problem, or indeed has an extension that covers it.

In short: you can, just don't presume it is a bug of either implementation.

1
  • 19
    "or could be that your code is wrong and one of them doesn't catch the problem, or indeed has an extension that covers it." – Or your code invokes Undefined Behavior, which means that both compilers can do whatever the hell they want, thus making both behaviors correct (and there's no problem to catch, because from the point of view of the compiler, there is no problem, it has some code that it is free to do with as it pleases). Commented Mar 30, 2016 at 3:09
24

Would it be on-topic to ask on SO if such behavior is a bug in g++ or not (e.g. something that is not standard)?

Sure, asking about programming tools, specific language standard and programming problems is on-topic.

0

As far as SO policies are concerned, such questions are perfectly fine.

The only problem with "this must be a compiler bug" is that unless you are a hardened veteran and you know it, it will come across as arrogant. Because the people who write compilers are usually pretty good programmers, and compilers have gone through very extensive testing.

The chance that some random student who just started to learn programming actually found a compiler bug, is non-existent. So before claiming that you have found a bug, try to be humble. It is quite likely that you are the "bug" yourself, for not understanding some subtle language detail.

That being said, after you've worked some 10+ years with programming, you'll find actual compiler bugs now and then. They are not rare. It is a very good idea to verify that it is indeed a bug on SO, before filing a bug report.

Not the answer you're looking for? Browse other questions tagged .