Compiling src/emu/sound.cpp...
../../../../../src/emu/sound.cpp: In member function 'void sound_manager::run_effects()':
../../../../../src/emu/sound.cpp:1001:32: error: 'm_phase' may be used uninitialized in this fu
nction [-Werror=maybe-uninitialized]
1001 | si.m_speed_phase = m_phase + (source_sample_index - source_samples);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../src/emu/sound.cpp:1002:14: error: 'dest_index' may be used uninitialized in this
function [-Werror=maybe-uninitialized]
1002 | eb.commit(dest_index);
| ~~~~~~~~~^~~~~~~~~~~~
../../../../../src/emu/sound.cpp:1001:55: error: 'source_sample_index' may be used uninitialize
d in this function [-Werror=maybe-uninitialized]
1001 | si.m_speed_phase = m_phase + (source_sample_index - source_samples);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
cc1plus.exe: all warnings being treated as errors
emu.make:1467: recipe for target '../../../../mingw-gcc/obj/x32/Release/src/emu/sound.o' failed
The errors you have are due to the compiler (gcc/g++) detecting that certain local variables (m_phase, dest_index, and source_sample_index) might be used before being initialized in the function sound_manager::run_effects(). Because you have -Werror=maybe-uninitialized enabled, these warnings are treated as errors, and compilation fails.
What the error means
maybe-uninitialized warning: The compiler has detected a path through the function where these variables could be used without having a defined value.
These variables are either local variables or member variables that the compiler cannot guarantee are initialized before use.
Even if logically you think they are initialized, the compiler cannot prove it (due to complex control flow, e.g.).
How to fix it
There are a few general approaches:
1. Initialize the variables when declared
This is the most straightforward fix. Find where the variables are declared, initialize them to zero or a safe default value.
Example:
cpp
float m_phase = 0.0f; // if float
int dest_index = 0; // if int
int source_sample_index = 0; // if int
Make sure these initializations match the expected type and logic of your code.
2. Ensure every code path initializes those variables before use
Look at the code of run_effects() carefully and find where these variables are assigned.
If an if/else or loop skips their initialization sometimes, restructure the code to guarantee they're always initialized.
You can write something like:
cpp
m_phase = some_value; // always assigned before use
dest_index = some_value;
source_sample_index = some_value;
Make sure that before the line where they are used (lines 1001, 1002), they have definitely been set.
This means the variables m_phase, source_sample_index, and dest_index might be uninitialized.
Here's a concrete way to approach the fix:
Clone or download the source
Open src/emu/sound.cpp and locate sound_manager::run_effects()
Search for the declarations of m_phase, dest_index, and source_sample_index inside that function.
Initialize them explicitly at declaration.
Example (hypothetical):
Suppose inside run_effects() you find:
cpp
float m_phase;
int dest_index;
int source_sample_index;
Change it to:
cpp
float m_phase = 0.0f;
int dest_index = 0;
int source_sample_index = 0;
If they are member variables
If m_phase is a member variable of sound_manager (or another class) and uninitialized, initialize it in the constructor.
For example, in the constructor of your class:
cpp
sound_manager::sound_manager()
: m_phase(0.0f)
{
// other initialization
}
Alternatively, suppress the warning (not recommended)
If you are confident the variables are initialized logically properly, and the warning is a false positive, you can disable the warning by adding compiler flags or using pragmas.
Example:
cpp
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
// Code causing warning/error here
#pragma GCC diagnostic pop
But fixing the code by initializing variables is better for code quality.
Summary
Initialize m_phase, dest_index, and source_sample_index before use.
If they are members, initialize in the constructor.
If local variables, initialize at declaration.
Review control flow to guarantee all execution paths assign values before usage.
As a last resort, disable -Werror or the warning for that code block.
If you want me to help more precisely, please share the snippet of sound_manager::run_effects() around lines 950-1050 from src/emu/sound.cpp. This will allow me to locate the variable declarations and suggest exact lines to change.