Rstudio does not display correct C++ diagnostics; libclang error

Hi Rstudio Community,

I'm running Rstudio 1.2.1327 on Windows 10. When editing C++ files, the C++ diagnostics are either absent or incorrect.

For example, when editing the following Rcpp file:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
  int n = x.size();
  return x * 2;
}

The diagnostics suggest that int n = x.size(); will cause an error because

"member reference base type 'Rcpp::NumericVector' (aka 'int') is not a structure or union."

In other contexts, e.g. when editing Rcpp files in a package, no diagnostics appear at all.
The Rstudio log file contains lines like:

18 Mar 2019 13:56:25 [rsession-Josh] ERROR Error parsing translation unit C:/Users/Josh/Documents/mypackage/src/my_rcpp_script.cpp; LOGGED FROM: class rstudio::core::libclang::TranslationUnit __cdecl rstudio::core::libclang::SourceIndex::getTranslationUnit(const class std::basic_string<char,struct std::char_traits,class std::allocator > &,bool) c:\jenkins\workspace\ide\windows\src\cpp\core\libclang\sourceindex.cpp:270

Other relevant info:

> devtools::session_info()
- Session info ------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/New_York            
 date     2019-03-18                  

- Packages ----------------------------------------------------------------------------------------
 package     * version date       lib source        
 assertthat    0.2.0   2017-04-11 [1] CRAN (R 3.5.1)
 backports     1.1.3   2018-12-14 [1] CRAN (R 3.5.2)
 base64enc     0.1-3   2015-07-28 [1] CRAN (R 3.5.0)
 callr         3.0.0   2018-08-24 [1] CRAN (R 3.5.1)
 cli           1.0.1   2018-09-25 [1] CRAN (R 3.5.1)
 crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.1)
 desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.1)
 devtools      2.0.1   2018-10-26 [1] CRAN (R 3.5.2)
 digest        0.6.18  2018-10-10 [1] CRAN (R 3.5.1)
 fs            1.2.6   2018-08-23 [1] CRAN (R 3.5.1)
 glue          1.3.0   2018-07-17 [1] CRAN (R 3.5.1)
 magrittr      1.5     2014-11-22 [1] CRAN (R 3.5.1)
 memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.1)
 pkgbuild      1.0.2   2018-10-16 [1] CRAN (R 3.5.1)
 pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.1)
 prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.1)
 processx      3.2.0   2018-08-16 [1] CRAN (R 3.5.1)
 ps            1.2.1   2018-11-06 [1] CRAN (R 3.5.1)
 R6            2.3.0   2018-10-04 [1] CRAN (R 3.5.1)
 Rcpp          1.0.0   2018-11-07 [1] CRAN (R 3.5.2)
 remotes       2.0.2   2018-10-30 [1] CRAN (R 3.5.1)
 rlang         0.3.0.1 2018-10-25 [1] CRAN (R 3.5.1)
 rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.1)
 rstudioapi    0.8     2018-10-02 [1] CRAN (R 3.5.1)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.1)
 usethis       1.4.0   2018-08-14 [1] CRAN (R 3.5.1)
 withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.1)

Would greatly appreciate any guidance here,
Josh

I'm not able to reproduce. Can you provide any other information?

Can you try executing:

.rs.setClangDiagnostics(2)

and then attempting to save to trigger RStudio diagnostics once more? You should then see some libclang diagnostic output in the console that might give some more information.

Sure, here's the output of .rs.setClangDiagnostics(2)

.rs.setClangDiagnostics(2)
Attemping to load libclang for x86_64-w64-mingw32 
C:/Program Files/RStudio/bin/rsclang/x86_64/libclang.dll
   LOADED: 5.0.2
> 

Restarting R session...

CLANG INDEXING: C:/Users/Josh/Documents/test.cpp
C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2\math.h:301:15: fatal error: 'math.h' file not found
  (Creating new index)
clang version 5.0.2 (tags/RELEASE_502/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "lib\clang\5.0.2\include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Program Files/RStudio/resources/libclang/builtin-headers/5.0.2
 C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2
 C:/PROGRA~1/R/R-35~1.1/include
 C:/Users/Josh/Documents/R/win-library/3.5/Rcpp/include
 C:/Users/Josh/Documents
End of search list.
C:/Users/Josh/Documents/test.cpp:6:12: error: member reference base type 'Rcpp::NumericVector' (aka 'int') is not a structure or union
TOTAL MEMORY: 22 mb (test.cpp)
PERFORMANCE 4415 ms (test.cpp)
CLANG INDEXING: C:/Users/Josh/Documents/test.cpp
CLANG REMOVE INDEX: C:/Users/Josh/Documents/test.cpp
  (Creating new index)
clang version 5.0.2 (tags/RELEASE_502/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "lib\clang\5.0.2\include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Program Files/RStudio/resources/libclang/builtin-headers/5.0.2
 C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2
 C:/PROGRA~1/R/R-35~1.1/include
 C:/Users/Josh/Documents/R/win-library/3.5/Rcpp/include
 C:/Users/Josh/Documents
End of search list.
C:/Users/Josh/Documents/test.cpp:6:12: error: member reference base type 'Rcpp::NumericVector' (aka 'int') is not a structure or union
TOTAL MEMORY: 22 mb (test.cpp)
PERFORMANCE 188 ms (test.cpp)
CLANG INDEXING: C:/Users/Josh/Documents/test.cpp
CLANG REMOVE INDEX: C:/Users/Josh/Documents/test.cpp
  (Creating new index)
clang version 5.0.2 (tags/RELEASE_502/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "lib\clang\5.0.2\include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Program Files/RStudio/resources/libclang/builtin-headers/5.0.2
 C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2
 C:/PROGRA~1/R/R-35~1.1/include
 C:/Users/Josh/Documents/R/win-library/3.5/Rcpp/include
 C:/Users/Josh/Documents
End of search list.
C:/Users/Josh/Documents/test.cpp:6:12: error: member reference base type 'Rcpp::NumericVector' (aka 'int') is not a structure or union
TOTAL MEMORY: 22 mb (test.cpp)
PERFORMANCE 179 ms (test.cpp)

I wonder if the use of a 'short' path for the R include directory is causing issues? I'm surprised because the includes look correct otherwise.

What do you see in the 'working' case, e.g. when you're working within a project?

The diagnostics look similar for the "working" case, except this time the error for int n = x.size(); no longer appears.

CLANG INDEXING: C:/Users/Josh/Documents/package/test.cpp
C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2\math.h:301:15: fatal error: 'math.h' file not found
  (Creating new index)
clang version 5.0.2 (tags/RELEASE_502/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "lib\clang\5.0.2\include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Program Files/RStudio/resources/libclang/builtin-headers/5.0.2
 C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2
 C:/Users/Josh/Documents/R/win-library/3.5/Rcpp/include
 C:/Users/Josh/Documents/R/win-library/3.5/RcppArmadillo/include
 C:/PROGRA~1/R/R-35~1.1/include
End of search list.
error: OpenMP support and version of OpenMP (31, 40 or 45) was disabled in PCH file but is currently enabled
PERFORMANCE 3307 ms (test.cpp)
CLANG INDEXING: C:/Users/Josh/Documents/package/test.cpp
  (Creating new index)
clang version 5.0.2 (tags/RELEASE_502/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "lib\clang\5.0.2\include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:/Program Files/RStudio/resources/libclang/builtin-headers/5.0.2
 C:/Program Files/RStudio/resources/libclang/builtin-headers/libc++/5.0.2
 C:/Users/Josh/Documents/R/win-library/3.5/Rcpp/include
 C:/Users/Josh/Documents/R/win-library/3.5/RcppArmadillo/include
 C:/PROGRA~1/R/R-35~1.1/include
End of search list.
error: OpenMP support and version of OpenMP (31, 40 or 45) was disabled in PCH file but is currently enabled
PERFORMANCE 9.0 ms (test.cpp)

Note the RcppArmadillo include now appears because I was already using Armadillo in my test R package (just to explain why it's new).

I'm still not able to reproduce, so any extra context you can provide to get a reproducible example would be helpful.

Here is the full Rstudio diagnostic report, maybe this will be helpful. Is there something else I could provide that would help?

[1] "1.2.1327"

$R
[1] "C:\\PROGRA~1\\R\\R-35~1.1\\bin\\x64\\R.exe"

$pdflatex
[1] "C:\\Users\\Josh\\AppData\\Roaming\\TinyTeX\\bin\\win32\\pdflatex.exe"

$bibtex
[1] "C:\\Users\\Josh\\AppData\\Roaming\\TinyTeX\\bin\\win32\\bibtex.exe"

$gcc
[1] ""

$git
[1] "C:\\PROGRA~1\\Git\\cmd\\git.exe"

$svn
[1] ""

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1    Rcpp_1.0.0     packrat_0.5.0 

SysInfo:
          sysname           release           version          nodename           machine             login              user 
        "Windows"          "10 x64"     "build 17134" "DESKTOP-PODOP7U"          "x86-64"            "Josh"            "Josh" 
   effective_user 
           "Josh" 

R Version:
               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          5.1                         
year           2018                        
month          07                          
day            02                          
svn rev        74947                       
language       R                           
version.string R version 3.5.1 (2018-07-02)
nickname       Feather Spray               
$ALLUSERSPROFILE
[1] "C:\\ProgramData"

$APPDATA
[1] "C:\\Users\\Josh\\AppData\\Roaming"

$CLICOLOR_FORCE
[1] "1"

$CommonProgramFiles
[1] "C:\\Program Files\\Common Files"

$`CommonProgramFiles(x86)`
[1] "C:\\Program Files (x86)\\Common Files"

$CommonProgramW6432
[1] "C:\\Program Files\\Common Files"

$COMPOSE_CONVERT_WINDOWS_PATHS
[1] "true"

$COMPUTERNAME
[1] "DESKTOP-PODOP7U"

$ComSpec
[1] "C:\\WINDOWS\\system32\\cmd.exe"

$DISPLAY
[1] ":0"

$DOCKER_CERT_PATH
[1] "C:\\Users\\Josh\\.docker\\machine\\machines\\default"

$DOCKER_HOST
[1] "tcp://192.168.99.100:2376"

$DOCKER_MACHINE_NAME
[1] "default"

$DOCKER_TLS_VERIFY
[1] "1"

$DOCKER_TOOLBOX_INSTALL_PATH
[1] "C:\\Program Files\\Docker Toolbox"

$DriverData
[1] "C:\\Windows\\System32\\Drivers\\DriverData"

$FPS_BROWSER_APP_PROFILE_STRING
[1] "Internet Explorer"

$FPS_BROWSER_USER_PROFILE_STRING
[1] "Default"

$GFORTRAN_STDERR_UNIT
[1] "-1"

$GFORTRAN_STDOUT_UNIT
[1] "-1"

$GITHUB_PAT
[1] "edited out"

$HOME
[1] "C:/Users/Josh/Documents"

$HOMEDRIVE
[1] "C:"

$HOMEPATH
[1] "\\Users\\Josh"

$LOCALAPPDATA
[1] "C:\\Users\\Josh\\AppData\\Local"

$LOGONSERVER
[1] "\\\\DESKTOP-PODOP7U"

$MSYS2_ENV_CONV_EXCL
[1] "R_ARCH"

$NO_PROXY
[1] "192.168.99.100"

$NUMBER_OF_PROCESSORS
[1] "12"

$OneDrive
[1] "C:\\Users\\Josh\\OneDrive"

$OneDriveConsumer
[1] "C:\\Users\\Josh\\OneDrive"

$OS
[1] "Windows_NT"

$PATH
[1] "C:\\Program Files\\R\\R-3.5.1\\bin\\x64;C:\\Program Files\\R\\R-3.5.1\\bin\\x64;C:\\Rtools\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Users\\Josh\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\Docker Toolbox;C:\\Users\\Josh\\AppData\\Roaming\\TinyTeX\\bin\\win32;C:\\Users\\Josh\\AppData\\Local\\atom\\bin"

$PATHEXT
[1] ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"

$PROCESSOR_ARCHITECTURE
[1] "AMD64"

$PROCESSOR_IDENTIFIER
[1] "Intel64 Family 6 Model 158 Stepping 10, GenuineIntel"

$PROCESSOR_LEVEL
[1] "6"

$PROCESSOR_REVISION
[1] "9e0a"

$ProgramData
[1] "C:\\ProgramData"

$ProgramFiles
[1] "C:\\Program Files"

$`ProgramFiles(x86)`
[1] "C:\\Program Files (x86)"

$ProgramW6432
[1] "C:\\Program Files"

$PSModulePath
[1] "C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules"

$PUBLIC
[1] "C:\\Users\\Public"

$QT_D3DCREATE_MULTITHREADED
[1] "1"

$R_ARCH
[1] "/x64"

$R_COMPILED_BY
[1] "gcc 4.9.3"

$R_DOC_DIR
[1] "C:/PROGRA~1/R/R-35~1.1/doc"

$R_HOME
[1] "C:/PROGRA~1/R/R-35~1.1"

$R_LIBS_USER
[1] "C:/Users/Josh/Documents/R/win-library/3.5"

$R_PACKRAT_DEFAULT_LIBPATHS
[1] "C:/Users/Josh/Documents/R/win-library/3.5;C:/Program Files/R/R-3.5.1/library"

$R_PACKRAT_SYSTEM_LIBRARY
[1] "C:/PROGRA~1/R/R-35~1.1/library"

$R_USER
[1] "C:/Users/Josh/Documents"

$RMARKDOWN_MATHJAX_PATH
[1] "C:/Program Files/RStudio/resources/mathjax-26"

$RS_LOCAL_PEER
[1] "\\\\.\\pipe\\37933-rsession"

$RS_RPOSTBACK_PATH
[1] "C:/Program Files/RStudio/bin/rpostback"

$RS_SHARED_SECRET
[1] "63341846741"

$RSTUDIO
[1] "1"

$RSTUDIO_CONSOLE_COLOR
[1] "256"

$RSTUDIO_CONSOLE_WIDTH
[1] "80"

$RSTUDIO_MSYS_SSH
[1] "C:/Program Files/RStudio/bin/msys-ssh-1000-18"

$RSTUDIO_PANDOC
[1] "C:/Program Files/RStudio/bin/pandoc"

$RSTUDIO_SESSION_PORT
[1] "37933"

$RSTUDIO_USER_IDENTITY
[1] "Josh"

$RSTUDIO_WINUTILS
[1] "C:/Program Files/RStudio/bin/winutils"

$SESSIONNAME
[1] "Console"

$SystemDrive
[1] "C:"

$SystemRoot
[1] "C:\\WINDOWS"

$TEMP
[1] "C:\\Users\\Josh\\AppData\\Local\\Temp"

$TERM
[1] "xterm-256color"

$TMP
[1] "C:\\Users\\Josh\\AppData\\Local\\Temp"

$USERDOMAIN
[1] "DESKTOP-PODOP7U"

$USERDOMAIN_ROAMINGPROFILE
[1] "DESKTOP-PODOP7U"

$USERNAME
[1] "Josh"

$USERPROFILE
[1] "C:\\Users\\Josh"

$VBOX_MSI_INSTALL_PATH
[1] "C:\\Program Files\\Oracle\\VirtualBox\\"

$windir
[1] "C:\\WINDOWS"

 [1] ".GlobalEnv"        "tools:rstudio"     "package:stats"     "package:graphics"  "package:grDevices" "package:utils"    
 [7] "package:datasets"  "package:methods"   "Autoloads"         "package:base"     
Log file: rdesktop.log
--------------------------------------------------

(Empty)

Log file: rsession-Josh.log
--------------------------------------------------

18 Mar 2019 13:45:32 [rsession-Josh] ERROR Error parsing translation unit C:/Users/Josh/Documents/package/src/test.cpp; LOGGED FROM: class rstudio::core::libclang::TranslationUnit __cdecl rstudio::core::libclang::SourceIndex::getTranslationUnit(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,bool) c:\jenkins\workspace\ide\windows\src\cpp\core\libclang\sourceindex.cpp:270
18 Mar 2019 13:45:32 [rsession-Josh] ERROR Error parsing translation unit C:/Users/Josh/Documents/package/src/test.cpp; LOGGED FROM: class rstudio::core::libclang::TranslationUnit __cdecl rstudio::core::libclang::SourceIndex::getTranslationUnit(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,bool) c:\jenkins\workspace\ide\windows\src\cpp\core\libclang\sourceindex.cpp:270
18 Mar 2019 13:45:36 [rsession-Josh] ERROR Error parsing translation unit C:/Users/Josh/Documents/package/src/test.cpp; LOGGED FROM: class rstudio::core::libclang::TranslationUnit __cdecl rstudio::core::libclang::SourceIndex::getTranslationUnit(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,bool) c:\jenkins\workspace\ide\windows\src\cpp\core\libclang\sourceindex.cpp:270

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.