View Issue Details

IDProjectCategoryView StatusLast Update
0002602OpenFOAMPatchpublic2017-07-05 17:29
Reporterhandrake0724 Assigned Towill  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux64OSLinuxOS VersionArch
Summary0002602: error in foamyHexMeshBackground.C
Descriptioncompiling foamyHexMeshBackground.C produces the following errors:

foamyHexMeshBackgroundMesh.C:314:28: error: binding 'const Foam::Field<double>' to reference of type 'Foam::scalarField& {aka Foam::Field<double>&}' discards qualifiers
     scalarField& fld = tfld();

foamyHexMeshBackgroundMesh.C:650:78: error: binding 'const Foam::fvPatchField<double>' to reference of type 'Foam::fvPatchScalarField& {aka Foam::fvPatchField<double>&}' discards qualifiers
                 fvPatchScalarField& fld = cellDistance.boundaryField()[patchi];


it is caused by the binding of const object to non-const object.
For a workaround, removing ampersand fix the problem.
a patch is attached.
TagsNo tags attached.

Activities

handrake0724

2017-07-04 12:52

viewer  

patch.diff (810 bytes)   
--- foamyHexMeshBackgroundMesh.C.old	2017-07-04 20:36:32.243096326 +0900
+++ foamyHexMeshBackgroundMesh.C	2017-07-04 20:32:07.826438328 +0900
@@ -311,7 +311,7 @@
 )
 {
     tmp<scalarField> tfld(new scalarField(points.size(), Foam::sqr(GREAT)));
-    scalarField& fld = tfld();
+    scalarField fld = tfld();
 
     // Find nearest
     List<pointIndexHit> nearest;
@@ -647,7 +647,7 @@
             forAll(fvm.C().boundaryField(), patchi)
             {
                 const pointField& cc = fvm.C().boundaryField()[patchi];
-                fvPatchScalarField& fld = cellDistance.boundaryField()[patchi];
+                fvPatchScalarField fld = cellDistance.boundaryField()[patchi];
                 scalarField patchDistSqr
                 (
                     fld.patch().patchInternalField(distSqr)
patch.diff (810 bytes)   

wyldckat

2017-07-04 14:58

updater   ~0008330

Questions:

 1. With which GCC version does this happen?

 2. With which OpenFOAM version is this happening?

handrake0724

2017-07-04 15:08

viewer   ~0008333

I am using GCC 6.3.0 with OpenFOAM 4.x

will

2017-07-05 16:43

manager   ~0008338

Again, confirmed. Both errors are caused by the explicit addition of "Ref" to the names of non-const access methods. The change doesn't seem to have been propagated to this specific bit of foamyHexMesh.

will

2017-07-05 17:03

manager   ~0008339

...probably because it's not being built by default. The build command in Allwmake has been commented out.

wyldckat

2017-07-05 17:12

updater   ~0008340

@will: See the following report and comments from when this was last looked into (as far as I know): https://bugs.openfoam.org/view.php?id=1205

This to say that I suspect that even if the code might now compile, I'm not so certain it will work properly :(

will

2017-07-05 17:27

manager   ~0008341

@wyldckat You might be right about the possibility of it not working, but the compilation is easy to fix, so I might as well do it now that it has been noticed.

will

2017-07-05 17:29

manager   ~0008342

@handrake0724 Thanks for the report. Resolved by commit 1ff57870007ac317d95a1756b41fd76c5a1e8f26 in dev, and 53b4b3fc2dfcaad06e3595993094cebe14d9aa55 in 4.x.

Issue History

Date Modified Username Field Change
2017-07-04 12:52 handrake0724 New Issue
2017-07-04 12:52 handrake0724 File Added: patch.diff
2017-07-04 14:58 wyldckat Note Added: 0008330
2017-07-04 15:08 handrake0724 Note Added: 0008333
2017-07-05 16:43 will Note Added: 0008338
2017-07-05 17:03 will Note Added: 0008339
2017-07-05 17:12 wyldckat Note Added: 0008340
2017-07-05 17:27 will Note Added: 0008341
2017-07-05 17:29 will Assigned To => will
2017-07-05 17:29 will Status new => resolved
2017-07-05 17:29 will Resolution open => fixed
2017-07-05 17:29 will Note Added: 0008342