Questions tagged [compiler-bug]
For questions about (suspected) incorrect behavior of a compiler. Use with the appropriate language tag and, where applicable, with the tag for the compiler in question.
295
questions
0
votes
1
answer
70
views
Compiler bug when implementing core::fmt::Write
When implementing core::fmt::Write for an avr serial monitor, calling unwrap on write_str writes what looks like a compiler error to the output. Calling write_fmt in any capacity crashes, but I think ...
2
votes
0
answers
64
views
Clang ignores `__attribute__((aligned))` when used with an alias template
For writing SIMD code, I'd like to use templates to generate vector types with certain alignment. However, clang seems to ignore the alignment attribute when used with an alias template instead of a ...
0
votes
0
answers
144
views
Different behavior with user defined default constructor (only MSVC)
I came across the following problem, with two classes X and Y where Y has a member of type X
If I then:
create a vector of objects of type Y via std::vector<Y> list = {{}}
and Y has a defaulted ...
2
votes
1
answer
94
views
Right bit shift in body of lambda used as a template argument doesn't compile on GCC
GCC doesn't compile this code, while other compilers (clang, msvc) do
template<auto T>
struct S { };
int main() {
S<[]{int x,y; x<<y;}> s1; // compiles fine
S<[]{int x,y; x&...
0
votes
1
answer
54
views
Why do I get different results for complex multiplication involving NaN with gcc depending on optimisation level?
Consider the following code:
#include <math.h>
#include <complex.h>
#include <stdio.h>
int main()
{
complex double A = CMPLX(-NAN, 0.0);
complex double B = CMPLX(NAN, 0.0);
...
5
votes
2
answers
103
views
Why does MSVC say a call to a virtual constexpr functional call operator does not result in a constant expression?
I have a class that wraps an array. It inherits from an abstract base class defining one virtual constexpr method for the function-call operator. In the child class, I override said method and access ...
30
votes
1
answer
1k
views
Double free in the C++ standard library using only std::function and std::shared_pointer
I recently came across a weird double-free bug in a program when capturing a shared_ptr in a lambda. I was able to reduce it this the following minimal example:
#include <memory>
#include <...
1
vote
0
answers
43
views
inference variable R has incompatible bounds
Today i experienced a strange error. The Strange was if i add the below code block in eclipse IDE it shows no error , but the same piece of code i compile it from cmd its showing error as
inference ...
1
vote
0
answers
57
views
Narrowing conversion from 'const char*' to 'bool' only in gcc [duplicate]
The following code compiles fine with msvc and clang but issues a narrowing warning for gcc 12.1. I think gcc is trying to do the wrong thing: It tries to convert const char* to bool even though there ...
1
vote
1
answer
247
views
Parameter pack referenced but not expanded in a using declaration: compiler bugs or not?
Consider the following code (also available here on compiler explorer)
#include <utility>
#include <type_traits>
template <std::size_t N, class = std::make_index_sequence<N>>
...
2
votes
1
answer
56
views
Variadic template template wrapper: weird compilers errors, possibly bugs
Over years of template metaprogramming practice, I have encountered all sorts of weird compiler bugs and errors. But with this one, I must say that I am somewhat puzzled. I have no idea which compiler ...
1
vote
1
answer
103
views
Xcode 13.3 Compiler Bug with multiple nil coalescing operators?
A colleague came up with an issue with the nil coalescing operator starting with Xcode 13.3 and 13.3.1 (Swift 5.6), which I was able to reproduce.
The following example always crashes, but worked fine ...
2
votes
1
answer
98
views
clang standard library bug or c++ undefined behavior?
Does the following C++ program contain any undefined behavior?
int
main()
{
struct entry
{
uint32_t hash;
uint32_t idx;
};
entry arr[31] ...
0
votes
0
answers
59
views
Why does the latest Clang still report missing default argument on a parameter pack? [duplicate]
#include<string>
enum Math { ONE };
template<Math math, class C, typename T = std::string, typename... Args>
void foo (T t = {}, Args&& ...) {}
class A {};
int main ()
{
foo<...
0
votes
0
answers
33
views
gcc not catching blatant uninitialized variable [duplicate]
I'm compiling this code with gcc 11.2.0 and the -Wuninitialized switch, but I don't get any warning in spite of bar_uninitialized being used uninitialized:
#include <vector>
#include <...
8
votes
1
answer
370
views
Wrong result of multiplication: Undefined behavior or compiler bug?
Background
While debugging a problem in a numerical library, I was able to pinpoint the first place where the numbers started to become incorrect. However, the C++ code itself seemed correct. So I ...
2
votes
0
answers
373
views
Is __builtin_ctzll(0) "undefined behavior" or just "undefined"?
GCC documentation says this about the __builtin_ctz family:
Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
Until now, ...
0
votes
0
answers
53
views
Why MSVC still compiles to error for calling a method after removing const-ness of the object?
To avoid complexity, below is a minimal example. For some reason, I have to pass normal object as const to some method and use it as such:
#include<iostream>
#define CALL(OBJECT, METHOD) \
...
-2
votes
1
answer
70
views
variable initialized wrong [closed]
i got a very strange problem with a variable that has name 'val'. I will try my best to explain it. I cannot make any small code example that do the same issue and my project is very big so can't ...
1
vote
0
answers
151
views
Is this a bug of clang 13 on [[likely]] attribute?
The following code is accepted by gcc 11.2, but rejected by clang 13:
struct A
{
int n = 0;
constexpr operator int() const noexcept
{
if (n >= 2) [[unlikely]]
{
...
4
votes
0
answers
66
views
GCC ambiguous inherited increment [duplicate]
The following code (simplified from a problem occuring with this NamedType library, see https://github.com/joboccara/NamedType/issues/61)
template<typename T>
struct PreIncrementable {
...
6
votes
2
answers
226
views
Why does gcc, with -O3, unnecessarily clear a local ARM NEON array?
Consider the following code (Compiler Explorer link), compiled under gcc and clang with -O3 optimization:
#include <arm_neon.h>
void bug(int8_t *out, const int8_t *in) {
for (int i = 0; i &...
2
votes
1
answer
96
views
C# Compiler bug: allows for conversion from Nullable<decimal> to decimal
Consider following code:
public class DecimalWrapper
{
public static implicit operator DecimalWrapper(decimal x) => new();
}
[Fact]
public void Test()
{
// ...
4
votes
1
answer
130
views
Can someone explain to me how this is undefined behavior?
I have this simple program which I compile with -O2.
Compiler version : g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
#include <cstdlib>
constexpr size_t NUM_ELEMENTS = 10000;
void init(float *a) {
...
1
vote
1
answer
192
views
Why is NVCC more strict with constexpr than non-constexpr host functions?
Consider the following code:
constexpr __host__ void foo() { }
__global__ void baz()
{
if constexpr(1==2) { foo(); }
}
this fails to compile with CUDA 11.3.1's NVCC. However, if I remove the ...
4
votes
1
answer
609
views
Is GCC correct to ignore the nodiscard attribute on overridden member functions?
Due to this question and the answers, it's not 100% clear whether attributes are inherited or not, but probably they're not since it's not stated in the standard. That's why if we have only the ...
6
votes
1
answer
140
views
Compiler variance for ambiguous copy-assignment from empty-braces
I've been trying to understand the rationale for std::nullopt_t to not be allowed to be DefaultConstructible in C++17 (where it was introduced) and beyond, and stepped over some compiler variance ...
0
votes
0
answers
103
views
Why is GCC not allowing me to capture something by reference, while Clang allows it?
This is with C++20 (-std=c++20), GCC 10.2.0 and Clang 11.1.0.
I have a class Graph with a data member prefix_to_presufs. In my code, I make a std::unique_ptr to a Graph like so:
auto gr{std::...
3
votes
1
answer
80
views
C++: MSC not resolving a template operator (gcc and clang ok)
I have a question about a C++ operator overloading on template class and type which is not correctly resolved by Microsoft Visual C++ while it is accepted by gcc and clang (Linux and macOS).
I suspect ...
2
votes
0
answers
102
views
readonly field not initialized - no warning
I have the following class with an obviously uninitialized readonly field. This compiles fine with no erros or warnings:
public class Test
{
readonly string s;
public string GetString() => ...
0
votes
1
answer
206
views
Cortex-M compiler generates improper FOR loop
Tested and reproduced on Cortex-M 4 and Cortex-M 0.
I have discovered an issue with the GCC compiler. When a function is declared as type int (non-void), and contains a for loop, but does not have a ...
3
votes
1
answer
384
views
Is this "possibly-uninitialized" compiler error a false alarm? [rustc 1.51.0]
I was hit with the possibly-uninitialized variable error, although I'm convinced that this should never be the case.
(The rustc --version is rustc 1.51.0 (2fd73fabe 2021-03-23))
fn example(...
1
vote
1
answer
212
views
Why does "Add IDL Method" on an Interface add the method to the Module as well as to the CoClass?
This question is about using Visual Studio 2019 for building an out-of-process COM server using ATL. (I have done this before in Borland but this is my first time using MSVC).
I created a project ...
7
votes
0
answers
154
views
Probable bug in MSVC with compile-time NaN comparison
My colleague was doing some basic experiments with NaN and was puzzled by the behavior on Visual Studio that did not match his expectations. After discussion, it seems that he uncovered a probable ...
10
votes
1
answer
214
views
C++ initializer list overload disambiguation
I have a question about C++ initializer list disambiguation which exhibits different behaviors between gcc, clang and Visual Studio.
I wonder if this is "undefined behavior" (incorrect ...
1
vote
2
answers
88
views
Can someone explain hard ilogical bug on C use of #define UMAX (a, b) ((a) > (b) ? (a) : (b)) directive, that returns lower value, in 2 compilers
I'm trying to identify the reason of a bug that happens on a MUD c code base. Where the use of the #define UMAX(a, b) ((a) > (b) ? (a) : (b)) , is used to return the max of two values.
It ...
0
votes
1
answer
48
views
Specifyin "enum" in a using statement - does it make a difference?
A "sanity check" question for language lawyers / nitpickers:
In this snippet of code:
enum my_enum { AValue1, AValue2 };
using alias_1 = enum my_enum;
using alias_2 = my_enum;
can there be ...
-1
votes
1
answer
106
views
Getting "instantiation resulted in unexecpted type" with MSVC
In a library of mine, I have the following bit of code (snipped for brevity):
namespace memory {
namespace managed {
namespace detail {
template <typename T>
inline T ...
2
votes
0
answers
154
views
Assigned register collision when inline assembly compiled with clang
Consider the following sample program (targeting Linux/x86-64):
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
unsigned arg1 = strtoul(argv[1], NULL, 0);
...
4
votes
2
answers
372
views
How to resize a std::vector<std::queue<std::unique_ptr<int>>>?
I'm trying to do the following:
#include <memory>
#include <vector>
#include <queue>
int main() {
std::vector<std::queue<std::unique_ptr<int>>> v;
v.resize(...
6
votes
1
answer
106
views
Constructing (but not destucting) an object of a class with a deleted or non-user-provided private destructor
Is the following snippet of code well-formed?
struct A { ~A() = delete; };
A *pa{new A{}};
class B { ~B() = default; };
B *pb{new B{}};
At a first glace it would seems as if the deleted dtor of A ...
3
votes
2
answers
78
views
Using typealias in place of typedef defined in class in definition
Why does this fail to compile? I am trying to reduce the amount of repetition since in the real code the class name is huge and the type is actually a very long name
https://godbolt.org/z/8YarWs
#...
32
votes
2
answers
1k
views
VBA takes wrong branch at If-statement - severe compiler bug?
The question mark in the title is only there because I'm very reluctant to call anything a compiler bug, but in this case, I'd be surprised if anyone could explain this behavior in any other way.
The ...
4
votes
1
answer
111
views
Waiving of access checking rules for explicit function template specializations in C++20
[temp.spec]/6 was added to C++20 by implementation of P0692R1 (Access Checking on Specialization) [emphasis mine]:
[temp.spec]/6 The usual access checking rules do not apply to names in a declaration ...
21
votes
8
answers
2k
views
"redundant cast to java.lang.Object" warning for necessary cast
Consider this Minimal, Reproducible Example :
interface Code {
static void main(String[] args) {
symbol(
String.valueOf(
true ? 'a' :
true ? 'b' ...
3
votes
3
answers
578
views
Duplicate symbols with global template variable using Clang
I have these three files
// foo.h
#pragma once
template <typename T> const T foo;
template <>
const int foo<int> = 1;
// a.cpp
#include "foo.h"
int main() {}
// b.cpp
#...
2
votes
0
answers
33
views
Is this a compiler bug - strange behavior of a function [duplicate]
I was testing this function and found the behavior is strange
method:
uint8_t func(uint32_t x) {
return std::min<uint8_t>(32, ::__builtin_clz(x)) + 1;
}
call this method func(0) returns 32 on ...
3
votes
0
answers
151
views
Clang memory sanitizer bug with SSE intrinsics
Here is a piece of code that generates an internal compiler error if I compile and run it with clang having memory sanitizer enabled.
It mainly just puts some data into an SSE register and calls a ...
1
vote
1
answer
70
views
Visual C++ compiler bug?
I've reduced my case as much as possible below.
#include <vector>
#include <atomic>
#include <chrono>
using namespace std;
class Unused
{
private:
vector<vector<...
15
votes
1
answer
388
views
MSVC: Invalid memcpy optimization?
Consider the following code:
void MemMove8(void* dst, void* src)
{
char tmp[8];
memcpy(tmp, src, 8);
memcpy(dst, tmp, 8);
}
MSVC (16.7.1) x86 with /O2 generates the following assembly for ...