clangd: In included file: unexpected OpenMP directive

Having an openmp pragma in a header results in the following error shown on the include.

In included file: unexpected OpenMP directive '#pragma omp parallel for’clang(omp_unexpected_directive) omp_header.hpp(4, 22): Error occurred here

Tested on the master from yesterday. Problem was already present in clangd 8.0.1 (no diagnostic is displayed, seen in the logs).

compile command clang++ -fopenmp main.cc

// header.hpp
#pragma once

void loop() {
#pragma omp parallel for
  for (int i = 0; i < 100; ++i) {
  }
}
// main.cc
#include "header.hpp"

int main() {
    loop();
}

The omp pragma seems to mess up the parsing of the header file somehow as I see some follow-up errors in the log:

V[14:12:23.340] Dropped diagnostic: /home/vogtha/tmp/omp_problem/main.cc: in included file: expected unqualified-id
V[14:12:23.346] index AST for /home/vogtha/tmp/omp_problem/main.cc (main=false): 
  symbol slab: 1 symbols, 4456 bytes
  ref slab: 0 symbols, 0 refs, 136 bytes
  relations slab: 0 relations, 24 bytes
V[14:12:23.347] Built preamble of size 202656 for file /home/vogtha/tmp/omp_problem/main.cc
V[14:12:23.347] Dropped diagnostic: /home/vogtha/tmp/omp_problem/main.cc: in included file: extraneous closing brace ('}')
V[14:12:23.349] index AST for /home/vogtha/tmp/omp_problem/main.cc (main=true): 
  symbol slab: 1 symbols, 4456 bytes
  ref slab: 1 symbols, 1 refs, 4256 bytes
  relations slab: 0 relations, 24 bytes

The problem was also reported here https://bugreports.qt.io/projects/QTCREATORBUG/issues/QTCREATORBUG-22225?filter=allissues (assuming they have clangd activated).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 39 (1 by maintainers)

Most upvoted comments

Fixed in 8035bb4a6573f7d20f17044a68a1405691000525

I’m also experiencing this linting error any time I have -fopenmp compile flag enabled and have a #pragma omp parallel directive anywhere in the headers included. Just to clarify - is clangd incompatible with OpenMP as of today? Any ETA for a fix?