TRIQS / tprf

TPRF: The Two-Particle Response Function tool box for TRIQS
https://triqs.github.io/tprf
Other
14 stars 12 forks source link

Error with clang 8.0 for structured binding declaration #11

Closed Stefan-Dienst closed 2 years ago

Stefan-Dienst commented 4 years ago

Dear all,

I have recently upgraded to clang 8.0 which resulted in an error when compiling tprf. The error occurs when I use a structured binding declaration for the MeshProduct and use the result in the make_gf function, e.g.

auto [wmesh, rmesh] = g_wr.mesh();
auto g_r = make_gf<cyclic_lattice>(rmesh, g_wr.traget());

The error message reads: reference to local binding 'rmesh' declared in enclosing function.

Does anyone know why this results in an error? I could compile without any problems with clang 6.0.

Cheers Stefan

Wentzell commented 4 years ago

Hey Stefan,

Can you give a complete minimal example?

Stefan-Dienst commented 4 years ago

Hey Nils,

sorry that it took me so long to answer.

While formulating a complete minimal example, I noticed that i described the problem improper. The above described error is only thrown if a structured binding declaration is used in combination with openmp.

So for example, using the following file in tprf:

#include "../types.hpp"
#include <omp.h>

namespace triqs_tprf {

g_wk_t test(g_wk_vt g_wk) {

  auto [wmesh, kmesh] = g_wk.mesh();

#pragma omp parallel for
  for(unsigned int idx = 0; idx < kmesh.size(); idx++) {}

    return g_wk;
}}

throws the error reference to local binding 'kmesh' declared in enclosing function 'triqs_tprf::test' for(unsigned int idx = 0; idx < kmesh.size(); idx++) {}

While

#include "../types.hpp"
#include <omp.h>

namespace triqs_tprf {

g_wk_t test(g_wk_vt g_wk) {

  auto wmesh = std::get<0>(g_wk.mesh());
  auto kmesh = std::get<1>(g_wk.mesh());

#pragma omp parallel for
  for(unsigned int idx = 0; idx < kmesh.size(); idx++) {}

    return g_wk;
}}

and

#include "../types.hpp"
#include <omp.h>

namespace triqs_tprf {

g_wk_t test(g_wk_vt g_wk) {

  auto [wmesh, kmesh] = g_wk.mesh();

  for(unsigned int idx = 0; idx < kmesh.size(); idx++) {}

    return g_wk;
}}

work fine.

Wentzell commented 4 years ago

Hi Stefan,

Have you tried if this problem persists with the most recent clang-9 compiler?

Can you convert the example into one that is ready to compile? We do not have your types.hpp

Stefan-Dienst commented 4 years ago

Hi Nils,

I have setup a app4triqs triqs repo only containing this problem here https://github.com/StefanKaeser/tests_for_triqs/tree/structured_binding.

Compiling this with clang 8.0 gives me the following error.

/home/kaeser/my_triqs_installations/tests_for_triqs.src/c++/tests_for_triqs/tests_for_triqs.cpp:14:35: error: 
      reference to local binding 'kmesh' declared in enclosing function
      'tests_for_triqs::test'
  for(unsigned int idx = 0; idx < kmesh.size(); idx++) {}
                                  ^
/home/kaeser/my_triqs_installations/tests_for_triqs.src/c++/tests_for_triqs/tests_for_triqs.cpp:11:16: note: 
      'kmesh' declared here
  auto [wmesh, kmesh] = g_wk.mesh();
               ^
1 error generated.

I have no yet tried clang-9, but will do.

Wentzell commented 2 years ago

This issue is resolved by recent versions of clang. Reopen if needed.