2,760 questions
3
votes
1
answer
86
views
Why does the compiler give strncpy 'stringop-truncation' warning only with -O2?
With avr-gcc 14, the compiler gives this warning:
avrenv.c: In function ‘main’
avrenv.c:12:13: warning: ‘strncpy’ output may be truncated copying 255 bytes from a string of length 509 [-Wstringop-...
9
votes
2
answers
188
views
How to correctly resolve unused warning when instance is being used in a fold operator
In the code below, I get the follow compilation warning:
error: variable 'process_arg' set but not used [-Werror=unused-but-set-variable]
const auto process_arg = [&]<typename T>(const ...
4
votes
2
answers
171
views
Clang doesn't warn about uninitialized stack variable
Had a bug in this code:
bool x;
for(const auto a : b)
{
x = x && a.b;
}
x should have initialized to true.
I'd like to raise a compiler error that the bool wasn't explicitly ...
2
votes
4
answers
441
views
How to suppress this false positive warning from Clang static code analyzer?
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int a;
} tempStruct1;
typedef struct {
int b;
} tempStruct2;
typedef struct {
tempStruct1 *temp1;
tempStruct2 *...
3
votes
1
answer
171
views
How to cause the CA2254 warning in your own library?
Let's say I want to wrap the classical LogInformation() method with a custom one:
public static void Info(this ILogger log, string message, params object[] objects) {
// ... some custom logic
...
0
votes
0
answers
65
views
Why is my Clang not checking the format string?
#include <stdio.h>
//extern int printf(const char* __restrict, ...) __attribute__ ((format (printf, 1, 2)));
void test_func(void);
void test_func(void) {
int test_object = 0;
printf(&...
4
votes
2
answers
188
views
Unexpected compiler warning - printf format specifiers
I have the following warning generated by a printf():
warning: format '%llu' expects argument of type 'long long unsigned int', but argument 7 has type 'uint64_t' {aka 'long unsigned int'} [-Wformat=]...
6
votes
0
answers
233
views
Is there an MSVC compiler option to warn about unsequenced modifications?
I have the following C code:
#include <stdio.h>
void MyFun(int a, int b)
{
printf("a = %d, b = %d\n", a, b);
}
int main(void)
{
int x = 1;
MyFun(++x, x++);
return 0;
}...
0
votes
0
answers
105
views
Can I trigger a compiler warning, and no linking error, with a templated declaration only?
I want to write a declaration, templated on a type, such that:
If not instantiated, triggers no compiler warnings or errors, even with strict warning flags.
If instantiated (e.g. by being used), ...
3
votes
2
answers
94
views
Should I care about Wcast-qual errors?
I recently read the NASA's power of 10 rules, and thought the rule about "using the compiler's most pedantic setting" was very interesting, considering warnings exist for a reason. I already ...
10
votes
1
answer
755
views
Why do compilers not warn about this null dereferencing, even when they detect it?
Consider the following program:
int main() {
int* ptr = nullptr;
return *ptr + 1;
}
(also on GodBolt)
How is it, that with "decent" warnings enabled (-Wall -Wextra), both popular ...
1
vote
1
answer
208
views
Function can't be called after std::unreachable if object constructed on stack?
Normally, I can place function calls after std::unreachable, and it has no effect. This works on MSVC, Clang, and GCC, except with GCC there is an extra detail that makes it fail compilation:
#include ...
2
votes
1
answer
167
views
How to initialize an enum when I do not know the exact type
My program contains a template function like this:
template<typename Key> Key getChoiceWidgetSelection(wxChoice& choiceWidget, bool *ok) {
Key ret;
*ok = false;
...
0
votes
1
answer
124
views
@nowarn is not working in Scala. Intellij Idea
I'm new to Scala and the @nowarn system seems a little bit confusing.
I've tryed to remove lint errors on Function1 and Function2 with nowarn, but it didn't work.
So, here's this programm:
import ...
7
votes
1
answer
226
views
Assignment in (else) if statement triggers warning in MSVC but not in gcc / clang
This code snippet triggers a warning in MSVC (VS2022 17.10.2).
int m = 0;
if(int i = m)
// ...
else if (int i = m) // warning C4456: declaration of 'i' hides previous local declaration
// ...
...
15
votes
1
answer
244
views
Can you warn/error when mixing char8_t and char32_t in expressions?
I have a code base which makes extensive use of char8_t and char32_t to represent UTF-8 code units and Unicode code points respectively.
A common mistake/bug in this code base is to compare char8_t to ...
-1
votes
1
answer
167
views
"React Hook useEffect has a missing dependency", but including it or removing the dependency array both make for incorrect behavior? [duplicate]
I am working on a React page that has a built in file manager.
I have a DocumentTable.js component, which is responsible for displaying the current list of files available, and it has (among others) ...
27
votes
5
answers
2k
views
With Clang or similar compilers, is it possible to turn only some warnings into errors?
Compiler warnings generally provide useful hints for common programming errors. It is often recommended to turn compiler warnings into errors (e.g. here). In my experience, this is useful to prevent ...
2
votes
1
answer
220
views
How to solve compiler warning for eigen library that contain characters that cannot be represented?
I got many compiler warnings for the eigen library, one example being:
Warning C4819 The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode ...
2
votes
0
answers
367
views
How do I avoid both modernize-deprecated-headers and misc-include-cleaner warnings?
I'm trying to remove all clang-tidy warnings in my C++ project. But I get alternating modernize-deprecated-headers and misc-include-cleaner warnings.
For example:
I use open_memstream in a file, so I ...
1
vote
1
answer
63
views
The equivalent of list initialization but with narrowing conversion
I want to provide a function to convert parameters, which are read as long long or long double from XML, to any type constructible from these types with narrowing conversion. But I want to use list ...
0
votes
0
answers
428
views
How to force the newer NuGet package version when there's a version conflict due to transitive references
I have a solution with 5 projects:
Project 1-3 are SDK-style projects with PackageReference.
Project 4 is a legacy .csproj project with packages.config (.NET Framework 4.7.2. WebForms + MVC 5 project ...
12
votes
1
answer
406
views
Avoiding strcpy overflow destination warning
With a structure such as the following
typedef struct
{
size_t StringLength;
char String[1];
} mySTRING;
and use of this structure along these lines
mySTRING * CreateString(char * Input)
{
...
1
vote
1
answer
585
views
Why is there no CS8604 (Possible null reference argument for parameter) warning in .NET Standard 2.1
When working with .NET Standard 2.1 code, I found a strange behaviour when there should have been a warning to a nullable parameter but it does not:
And I can reproduce it with a simple method:
#...
0
votes
1
answer
66
views
Inconsistent reporting of obsolete member usages
Consider this class:
public class Number
{
[System.Obsolete()] public string ToExactString() => "";
[System.Obsolete()] public override string ToString() => "&...
6
votes
1
answer
342
views
Why does 'this-escape' warning trigger when calling final methods from the superclass
Java 21 introduces a new this-escape warning which warns against situations where a constructor is calling a method which can be overriden by a subclass. This is a potentially dangerous situation ...
-2
votes
1
answer
154
views
Why does Java not give any warning on downcasting? [closed]
I don't understand the philosophy behind the Java compiler not warning on downcasting when it think it may potentially succeed. In particular, the following compiles without any warning (and I am ...
1
vote
1
answer
59
views
C# help compiler to infer nullability
Conside this simple class in C# (nullability feature enabled):
public class Error
{
public string Message = "...";
public static implicit operator bool(Error? err) => err is not ...
2
votes
2
answers
232
views
.NET 8 & Blazor components nullable warning with @ref
From what I understand the recommended method to hide null warnings on services is the following:
[Inject] private IExampleService ExampleService { get; set; } = default!;
https://learn.microsoft.com/...
3
votes
3
answers
159
views
How do I resolve the "control reaches end of non-void function" warning in the case with a custom error handler?
Consider the following example:
a.c:
#include <stdlib.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
char *invocation_name;
static void handle_error(const char* ...
1
vote
2
answers
117
views
Getting warnings for using void * while trying to recode printf
I'm trying to set up an array of functions that takes in functions that need different variables (for example, my_putchar needs a char while my_put_nbr needs an int), so I just decided to define it ...
7
votes
0
answers
2k
views
Warning about unsafe for trimming and AOT compatibility if passed across the WinRT ABI (List<T>)
I have a simple .NET 8 (C#) class library that reads some registry values.
It was created and built in Visual Sudio 2022 (64 Bit) v17.11.5.
PROJECT FILE:
<PropertyGroup>
<TargetFramework&...
0
votes
0
answers
85
views
Warning flags for accumulation of floating-point as integers?
What warning on GCC and/or clang do I need to activate for this to give a warning?
#include<numeric>
...
std::vector<double> vec = {1.0, 2.0, 3.0};
auto const sum = std::accumulate(vec....
3
votes
0
answers
108
views
Why does -Wall -Wextra -Wpedantic not include -Wsign-conversion with clang?
Consider the following program:
#include <stdint.h>
#include <stdio.h>
int64_t foo(void) {
return -1;
}
int main(void) {
size_t x = foo();
printf("x = %zu\n", x);
...
0
votes
1
answer
275
views
Warning failed to resolve include moc_predefs.h - VS2022 Qt5.15.2
I have a project written in Visual Studio 2022 c++ with Qt5.15.2 (x64).
It comiles and works just fine.
During compilation I get a warning for each widget-derived-class in my project.
Moc'ing ...
0
votes
1
answer
150
views
gfortran execution bug when compiled with optimization if some variable is declared "intent(out)"
The following Fortran code should give a value close to 2/3.
! File "buggy.f90".
program buggy
implicit none
integer, parameter :: n = 1000
integer :: i, k
logical :: c1, c2
real,...
4
votes
2
answers
688
views
How to enable code analysis IDE0058 as a build error?
I want to enable IDE0058 as an error during build. Here's how I attempted to do that.
Start Visual Studio 2022 (Version 17.11.2)
Create new project. Project type: C#, Windows, Console -> Console ...
5
votes
2
answers
159
views
Why -Wunused-value does not catch a statement `true;`?
Given following C code:
#include <stdbool.h>
int main (void)
{
true;
return 0;
}
I expect that -Wunused-value would cause a warning at line 5: true;
because this statement does ...
-2
votes
2
answers
162
views
Different notes for uninitialized member inside a generic lambda in GCC 9 and GCC 10
I have noticed an inconsistent behavior in my production C++17 code regarding generic lambdas and notes. I was finally able to break it down to the following minimal example.
Gives a note with x86_64 ...
0
votes
1
answer
492
views
How to silence warnings from 3rd party includefiles with Meson and GCC
It looks like meson is picking compiler flags from pkg-config and consequently setting include paths to dependencies using the -I flag. This leads to annoying warnings if you start turning on enough ...
-2
votes
1
answer
145
views
Warning to discover unnamed variable
Recently I've met a bug in C++ project related to an unnamed scope guard, like in this question:
LockGuard(mutex);
See simple demo.
This kind of bug is really hard to find by reviwing changes, and ...
1
vote
2
answers
87
views
Alternatives to self assignment for 'breakpoint code'
I recently tried to build a project with clang and clang++. Up to now it has only been built with GCC.
One of the problems that I saw was with code that is of the following form
if (expression)
{
...
1
vote
1
answer
118
views
Getting Warning BL0005 when modeling data for EditForm in Blazor
I am doing something like this in the Blazor HTML section...
<EditForm EditContext="editContext" OnValidSubmit="SubmitQuery">
<DataAnnotationsValidator />
<...
2
votes
2
answers
405
views
Understanding How the Compile Function Works in SBCL Common Lisp
I was hoping someone can explain why the compile function is not working as I would expect.
First question:
* (compile 'square (lambda (x) (* x x)))
SQUARE
NIL
NIL
But then:
* (square 3)
; in: SQUARE ...
3
votes
0
answers
83
views
signed overflow warning when extracting/inserting a timepoint from/to streams
When specifying the command line options -Wstrict-overflow=4 and -O3, extracting a timepoint (e.g. std::chrono::local_seconds) from a stream object triggers some warnings from GCC (v14.1). Inserting a ...
0
votes
1
answer
149
views
Misleading unreachable warning when a type pattern match that is the result of a inline expansion is involved?
The following method works fine when T and the types of all its components are specific types (contrary to abstract type parameters).
import scala.compiletime.*
private inline def loop[T <: Tuple, ...
0
votes
1
answer
437
views
Cannot assemble my code: waring: warning: relocation in read-only section `.text', warning: creating DT_TEXTREL in a PIE
I tried to replicate the assembly workspace that i have to study on my windows pc (where i have instruction to how installe and use wsl) on my linux pc but when i try to assemble by using
./assemble....
0
votes
0
answers
123
views
Can I ask GCC to give me a warning or error on empty structs?
I just had the worst problem ever in my mixed C/C++ project.
The C code is the production code, the C++ is the testing environment. We are compiling with MinGW GCC, but developing on Qt Creator which ...
1
vote
1
answer
567
views
Terraform Warning: Interpolation-only expressions are deprecated
I got this warning:
Warning: Interpolation-only expressions are deprecated
on best.tf line 69, in locals:
69: pools = length(var.instances) > 0 ? { "${var.name}" = var....
0
votes
0
answers
67
views
Windows CPP compiler ignore specific warnings and treat every warning as error
I am following this documentation
I want to treat all warnings as error and ignore these specific warnings but I get an error:
set _CL_="-WX -WD28020 -WD28112 -WD28132 -WD28159 -WD28182 -WD28195 -...