Repository navigation
Description
System details
RStudio Edition : Desktop
RStudio Version : Version 1.3.1056
OS Version : Windows 10 x64 (build 18362)
R Version : 3.6.3 (2020-02-29)
Steps to reproduce the problem
Create a new package project
install.packages("devtools")
devtools::install_github("r-lib/usethis")
install.packages("cpp11")
usethis::use_cpp11()
Create a new file at src/testfile.cpp
add this content:
#include "cpp11.hpp"
using namespace cpp11;
[[cpp11::register]]
double sum2(doubles x) {
double total = 0;
for(auto it = x.begin(); it != x.end(); ++it) {
total += *it;
}
return total;
}Describe the problem in detail
First, I think this issue may be relate to #6384 and/or #4457
I first reported the issue at r-lib issues link, and to avoid repetition, I ask you to look there what I reported.
But in synthesis: What I found is that libclang is not parsing correctly the namespaces and report for example that cpp11::doubles does not exist.
RStudio from 1.3 (IIRC) started to use libclang 5.0.2 (in order to allow c++14). In older versions (RStudio Desktop 1.1.463 version) it used the version 3.4.0, and libclang parses the headers correctly.
I also tested in Ubuntu 16.04 LTS, with the same problems (and the solutions also worked).
Using .rs.setClangDiagnostics(2) you can see that the current libclang throws errors parsing the headers.
What I did and worked:
- In Ubuntu, I installed the lastest libclang (version 10 IIRC) and that still giving the same issues.
- So I installed the old version 3.4.0, and the problem was solved.
- In windows, I copied the libclang files from the old RStudio over the new RStudio, and the problem was solved.
Has this anything related to Rtools that is not prepared for the new libclang? or RStudio?
Thanks.
Describe the behavior you expected
- The parsing being correct
- I have read the guide to submitting good bug reports at https://github.com/rstudio/rstudio/wiki/Writing-Good-Bug-Reports .
- I have installed the latest version of RStudio and confirmed that the issue still persists.
- If I am reporting a RStudio crash, I have included a diagnostics report. https://support.rstudio.com/hc/en-us/articles/200321257-Running-a-Diagnostics-Report
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Activity
ronblum commentedon Aug 13, 2020
@franzbischoff Thank you for raising the issue! I'll mark for review as part of our ongoing development of RStudio.
franzbischoff commentedon Dec 14, 2020
Just tried with a bunch of LLVM versions, 3.7.0 works.
I see that clang is looking inside these folders:
But the weirdest thing is that
<stdint.h>and<cstdint>are there in those folders, and even if I#includethem in my file, libclang (new versions) still missing the intxx_t defines.R-Hannibal commentedon Feb 12, 2021
@kevinushey - do you think a libclang update on our end would address this issue?
franzbischoff commentedon Feb 12, 2021
After migrating from RStudio to VSCode (only for Rcpp purpose) and dealing with clang directly, I say that it is not a bug in clang, but some include path is not well referenced to clang parser by RStudio.
kevinushey commentedon Feb 16, 2021
The problem (IIUC) is that even though we're including the bundled libclang headers, we're not including the Rtools toolchain headers.
franzbischoff commentedon Feb 16, 2021
Right @kevinushey , the parser starts by not finding the stdlib functions/defines and stop by limit of errors.
github-actions commentedon Nov 27, 2021
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.
stale commentedon Dec 11, 2021
This issue has been automatically closed due to inactivity.
mikebessuille commentedon Feb 7, 2022
Related to #10514
26 remaining items
gtritchie commentedon May 13, 2022
For the testing I did above, I started with a clean Windows-10 VM, then installed R 4.1.3, RTools 4.0, and RStudio 2022.06.0-daily+403 (Qt).
Then tried the repro steps from this issue, and let it install all the R packages it wanted.
Then, on the same VM, I installed R 4.2.0 and RTools 4.2, started RStudio while holding down Ctrl and picked R 4.2, then had it load the same project, and re-ran the commands in the repro steps, e.g.:
Then I enabled clang diagnostics and saw the error.
gtritchie commentedon May 13, 2022
Assigning back to @kevinushey, he said he'd like to take a look at this.
gtritchie commentedon May 23, 2022
Tried the scenario again on a clean Windows-10 VM. Installed:
Then in RStudio console:
Then created a new package project, followed by:
Note those error messages at the end. Not sure if they matter?
Now I created the testfile.cpp with content as described in the repro steps. I did not see the problem originally described (no longer got the parsing error about unknown type name "doubles") and if I put in an intentional error, it was flagged.
Then I turned on clang diagnostics, and here's what I saw:
kevinushey commentedon May 23, 2022
This is probably coming from here:
rstudio/src/cpp/session/modules/SessionClang.R
Lines 175 to 179 in 7cd20f0
I think we need to handle this specially for Rtools40.
(Those paths are only real within a MinGW shell; we should instead just use
gcc.exeandg++.exeexplicitly after ensuring Rtools is on the PATH.)The other compiler warnings, I suspect, are another case of where we need to tell libclang to "pretend" to be gcc instead of MSVC.
kevinushey commentedon May 26, 2022
To spare @gtritchie from testing this once again, I verified this now works as expected with:
For posterity:
And, with:
I see:
and code completion + diagnostics all appear to work as expected.