Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

76
Vistas
Passing the tuple by reference into lambda causes null pointer dereference warning

I have the following piece of code:

boost::circular_buffer<std::tuple<float, float, float>> foo;
foo.push_front(std::make_tuple(3.1f, 1.5f, 1.2f));
foo.push_front(std::make_tuple(3.6f, 1.1f, 1.7f));
foo.push_front(std::make_tuple(3.2f, 1.1f, 1.9f));

const float bar = 3.5f;

// find the first tuple for which the first element is greater than bar
auto firstGreater = std::find_if(foo.begin(), foo.end(), [bar](const auto &t) {
    return std::get<0>(t) > bar;
});

When compiling this code with GCC version 7.5.0 or 9.3.0 (did not try with other versions) with a flag -Wnull-dereference, I get a warning in the return statement of the lambda:

error: potential null pointer dereference [-Werror=null-dereference]
139 |                         return std::get<0>(t) > bar;
    |                                ~~~~~~~~~~~~~~~^~~~~

Interestingly enough, when the tuple is passed to the lambda by value instead of by reference, the warning is gone:

auto firstGreater = std::find_if(foo.begin(), foo.end(), [bar](auto t) {
    return std::get<0>(t) > bar;
});

I am trying to understand why that would be the case since a reference cannot point to nothing, but can't figure out the root of the issue. Any ideas why this might happen?

Note: the above snippet is just a sample, but it does reflect the essence of what is going on in the real code. Although it may not be enough to reproduce the warning

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda